Talk

Difference between revisions of "Client-side form validation"

From Joomla! Documentation

(New page: == 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; ...)
 
Line 8: Line 8:
 
   JRequest::checkToken() or jexit( 'Invalid Token' );
 
   JRequest::checkToken() or jexit( 'Invalid Token' );
 
   $email = JRequest::getString('email', ''); // start email validation
 
   $email = JRequest::getString('email', ''); // start email validation
   if($email != '') // email is not required but if isset must be valid
+
   if($email != null) // email is not required but if isset must be valid
 
   {
 
   {
 
   jimport( 'joomla.mail.helper' );
 
   jimport( 'joomla.mail.helper' );

Revision as of 21:26, 13 March 2009

Validation works, but..[edit]

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))