mraquinn Posted January 7, 2009 Share Posted January 7, 2009 Hi, I'm working on a Drupal-based site and creating a contact form with Webform. I have these two snippets of code to add to the form to validate the email addresses; the first checks the email address is a valid one (to a small extent) and the second one compares the two given addresses to ensure they are the same. What I can't do is combine these into one function so that I can use it in Webform. Could anyone help please? Also, any suggestions on making the first function better are appreciated. Thanks! <?php $email_address = $form_values['submitted_tree']['email_address']; if (strlen(trim($email_address)) > 0) { if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email_address)) form_set_error('submitted][email_address', t('Your email address is not valid.')); }; ?> <?php if ($form_values['submitted_tree']['email1'] != $form_values['submitted_tree']['email2']) { form_set_error('submitted][email1', t('E-mail addresses must match.')); } ?> Link to comment https://forums.phpfreaks.com/topic/139826-webform-validation-functions/ Share on other sites More sharing options...
gevans Posted January 7, 2009 Share Posted January 7, 2009 You mean something like this? <?php function checkEmail($email1,$email2){ $email_address = $email1; $email_address_check - $email2; if (strlen(trim($email_address)) > 0) { if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email_address)) return form_set_error('submitted][email_address', t('Your email address is not valid.')); } if ($email_address !== $email_address_check) { return form_set_error('submitted][email1', t('E-mail addresses must match.')); } return TRUE; } $result = checkEmail($form_values['submitted_tree']['email1'], $form_values['submitted_tree']['email2']); ?> Link to comment https://forums.phpfreaks.com/topic/139826-webform-validation-functions/#findComment-731545 Share on other sites More sharing options...
mraquinn Posted January 7, 2009 Author Share Posted January 7, 2009 Hi and thanks for your help. For whatever reason that always returns the error message that the emails don't match, even when they do....which is odd. Link to comment https://forums.phpfreaks.com/topic/139826-webform-validation-functions/#findComment-731709 Share on other sites More sharing options...
mraquinn Posted January 11, 2009 Author Share Posted January 11, 2009 Any ideas how to get this working? ??? Link to comment https://forums.phpfreaks.com/topic/139826-webform-validation-functions/#findComment-734706 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.