Forums

Password field

penny 28 Sep, 2015
Hi,

I have a form and I would like people to enter a set password in order to submit the form.
There will be a single password ( Ex:12345), after the password has been entered and all validation is checked the form will submit and send the email.

How do I add validation to the password field to check if the password that is entered is correct and the form is submitted?

I was reading the following -http://www.chronoengine.com/faqs/54-cfv4/cfv4-validation/2592-how-do-i-use-custom-serverside-validation.html - But it says at the bottom that V5 doesn't have custom server validation. So I set up the Event switcher and have the following code in it

<?php
$password =& $form->data['password'];
if ( !isset($password) || !$password || $password != '12345' ) {
$form->validation_errors['password'] = 'Please enter a valid password';
return false;
}
?>

The event switcher is at the top of the onload with an event loop in the fail

Thanks
Penny
GreyHead 28 Sep, 2015
Hi Penny,

The syntax has changed a bit in CFv5 you need here to return 'fail' rather than false and I'm not clear about how how the error messages are set up (I just peeked at the code but didn't find a simple answer). A Joomla! system message should work OK:
<?php
if ( empty($form->data['password']) || $form->data['password'] != '12345' ) {
  $app = JFactory::getApplication();
  $app->enqueueMessage('Please enter a valid password', 'error');
  return 'fail';
}
?>

Bob

[[>> later - fixed typos <<]]
penny 28 Sep, 2015
Hi,

Thanks, but I still seem to be doing something wrong. When the form is loaded the password field is already filled out, when I enter all the information in the form and leave the password field the form is submitted and an email is sent. In my debug code I see [password] => a+E8h79}2n (which would be the already set password)

Penny
GreyHead 28 Sep, 2015
Hi Penny,

It may be your browser auto-completing the password. You can add autocomplete='off' to the input to try to prevent that,

I'm not clear why that password would get past the Event Switcher check though.

Bob
penny 28 Sep, 2015
Hi,

Ok. So I have added the Autocomplete = off.
The field is empty in Firefox but is not in Chrome, Which really doesn't matter, But it is still passing the wrong password and not checking it and completing the form. Am I missing some other setting?
GreyHead 28 Sep, 2015
Hi Penny,

Sorry the code I posted had some typos :-( There were two ] missing after ['password' - I've corrected that now.

Bob
penny 01 Oct, 2015
Bob,

Thanks for that. It is now working, but when the password is entered wrong I don't get the error msg.

Penny
penny 01 Oct, 2015
Bob,

NM - I just noticed my template did not have the Display notices.

Thanks
Penny
This topic is locked and no more replies can be posted.