Talk:Client-side form validation

From Joomla! Documentation
(Difference between revisions)
Jump to: navigation, search
m (Add "validate" to the button class: new section)
Line 27: Line 27:
  
 
([[User:Dangerfield|Dangerfield]] 19:58, 13 March 2009 (UTC))
 
([[User:Dangerfield|Dangerfield]] 19:58, 13 March 2009 (UTC))
 +
 +
== Add "validate" to the button class ==
 +
 +
I think this a great feature in the Joomla 1.5, and wish more developers implemented it in their forms.
 +
 +
The best example of this in action is on the Joomla 1.5 registration form. \components\com_user\views\register\tmpl\default.php.
 +
 +
I am not sure why they left out adding "validate" to the button class, but it is essential to performing the validation on submit.

Revision as of 10:53, 6 May 2009

Validation works, but..

On a component of my own in backend, this makes the validation, returns the error, but data in the form are lost:

function save()
{
 global $mainframe;
 JRequest::checkToken() or jexit( 'Invalid Token' );
 $email = JRequest::getString('email', ); // start email validation
 if($email != null) // email is not required but if isset must be valid
 {
 jimport( 'joomla.mail.helper' );
     if (!JMailHelper::isEmailAddress($email))
     {
     $mainframe->enqueueMessage('Email not valid', 'error');
     return $this->execute('edit');
     }
  }
  $row =& JTable::getInstance('mytable', 'Table');		
  if (!$row->bind(JRequest::get('post'))) 
     {
     JError::raiseError(500, $row->getError() );
     }
}  

What's wrong here? Any suggestion to retrieve the data that I was filling before the validation stop..?

(Dangerfield 19:58, 13 March 2009 (UTC))

Add "validate" to the button class

I think this a great feature in the Joomla 1.5, and wish more developers implemented it in their forms.

The best example of this in action is on the Joomla 1.5 registration form. \components\com_user\views\register\tmpl\default.php.

I am not sure why they left out adding "validate" to the button class, but it is essential to performing the validation on submit.

Personal tools
Namespaces

Variants
Actions
Navigation
Joomla! Sites
Toolbox