I am having a weird issue with my form validations. I have 4 inputs in my form and they are all being validated.
Everything works fine until it validates my last input field which is an email input field. I have two rules set on the email input field, 'rule' => 'notEmpty' , 'rule' => 'email'. The form validates and posts just fine when it only has to check for notEmpty rule but if an invalid email is found it does validate it but it doesn't post even after you input a valid email.
Here are some scenarios:
One: User inputs valid entries for all the inputs
Everything works fine, the form posts and the data is added to the database.
Two: User inputs valid entries for all but the email input but then enters a valid emails in all inputs
Assuming that the user hits submit after only providing input for the first three fields
Everything works fine after they input a valid email address on the first go, the form posts and data is added to the database.
Three: User inputs valid entries for all except the email (provides an invalid email)
It displays the error message but even after providing a valid email address it doesn't do anything. I notice that the page keeps reloading with the same data if you keep clicking the submit button.
Also, the error message goes away if the submit button is clicked again after the initial click
Here is my Model:
class Member extends AppModel
{
public $validate = array(
'id' => array(
'rule' => 'notEmpty'
),
'Student_First_Name' => array(
'rule' => 'notEmpty'
),
'Student_Last_Name' => array(
'rule' => 'notEmpty'
),
'Student_Email' => array(
'emailRule-1' => array(
'rule' => 'notEmpty',
'last' => false
),
'emailRule-2' => array(
'rule' => 'email',
'message' => 'Please enter a valid email address.'
))
);
}
Here is the Controller:
class MembersController extends AppController
{
...
public function add()
{
if($this->request->is('post'))
{
$this->Member->create();
if($this->Member->save($this->request->data))
{
$this->Session->setFlash('Member has been added!');
$this->redirect( array( 'action' => 'members'));
}
else
{
$this->Session->setFlash('Unable to add member.');
}
}
}
}
I apologize for such a long post for such a simple/annoyance problem but I hate having stuff like this in my applications/websites.
Thank you.
'last' => false? makes no sense to me.. if one didnt input any email there is no need to also check on a valid form of email... - mark