Hi
I'm sitting on the dumbest thing for a lot of hours.

How can i check if two fields?(emails) are the same?

I'm using a regular FAPI

I've created 2 elements

$form['email'] =  array(
    '#title' => t('Email'),
    '#type' => 'emailfield',
    '#default_value' => !empty($form_state['values']['email']) ? $form_state['values']['email'] : '',
  );

  $form['email_verification'] =  array(
    '#title' => t('Email verification'),
    '#type' => 'emailfield',
    '#default_value' => !empty($form_state['values']['email_verification']) ? $form_state['values']['email_verification'] : '',
  );

How can i check if those 2 are the same??
10x!

Comments

doronsever’s picture

Well, one thing working with drush is that you don't always remember that the module is based on another module.
this time its Form API Validation.

to check if 2 items are equal you need to add the match_field[otherfield] rule.

for my exmple

$form['email_verification'] =  array(
    '#title' => t('Email verification'),
    '#type' => 'emailfield',
    '#default_value' => !empty($form_state['values']['email_verification']) ? $form_state['values']['email_verification'] : '',
    '#rules' => array('match_field[email]'),
  );

Hope it helps some one :)

attiks’s picture

Status:Active» Fixed

Glad it works

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

ARUN AK’s picture

Priority:Critical» Normal
Status:Active» Closed (fixed)

Hi,

I have tried this, it did not work as well,

What I did is, I have a added a new custom field in to user registration form. I want to check default user account email field and my custom email field having same value.

My code:

<?php
function mymodule_form_user_register_form_alter(&$form, &$form_state) {
   
$form['#validate'][] = '_user_register_form_validate'; // Add custom validation with user registration form.
   
$form['account']['email_confirm'] = array(//Adding Extra Re-enter e-mail field.
      
'#type' => 'textfield',
      
'#title' => t('Re-enter e-mail'),
      
'#required' => TRUE,
      
'#weight' => '-3',
      
'#description' => '',
       
'#rules' => array('match_field[mail]'),
     );
}
?>

If I disable clientside validation for this form, then 'match_field' validation working with normal php form submission. But match_field validation is not working with clientside validation.

Please help.

ARUN AK’s picture

Priority:Normal» Critical
Status:Closed (fixed)» Active
attiks’s picture

Status:Closed (fixed)» Active

Do you get any errors in the browser? Are all needed submodules enabled?

attiks’s picture

Issue summary:View changes

put the code in code tags

Jelle_S’s picture

Issue summary:View changes
Status:Active» Fixed

match_field support added to latest dev version.

Status:Fixed» Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.