0

I want to prevent validation check on the field_abc ?
How can I prevent validation for a field_abc

  function test_mail_menu() {
         $items['test-mail-1'] = array(
            'page callback' => 'drupal_get_form',
            'page arguments' => array('test_mail1_form'),
            'type' => MENU_CALLBACK,
            'access arguments' => array('access content'),
          );

    return $items;
    }
    function test_mail1_form ($form,$form_state) {
      $form = array();
      $form['field_abc'] = array(
        '#type' => 'textfield',
        '#title' => t('ABC'),
        '#validated' => TRUE,
     );

      $form['submit-button'] = array(
        '#type' => 'button',
        '#title' => t('sub'),
      );


      $form['#submit'][] = 'test_mail1_submit';
      $form['#validate'][] = 'test_mail1_validate';
      return $form;
    }

    function test_mail1_submit($form,&$form_submit) {



    }

    function test_mail1_validate($form, &$form_state) {



      if (!(is_numeric($form_state['input']['field_abc']))) {

        form_set_error('field_abc','ERROR');

      }
    }
  • why do you have submit-button and submit? – Mohammed Shameem Oct 10 '13 at 11:55
  • I just have single submit button. I have not written anything inside of submit function as of now . – harshal Oct 10 '13 at 11:59
  • $form['submit-button'], and $form['submit'] why do you have these two? – Mohammed Shameem Oct 10 '13 at 12:01
  • Yes, that $form['submit'] looks like a culprit. I'd remove it before proceeding. – Alfred Armstrong Oct 10 '13 at 12:03
  • I just wanted to check if on submit whether I get errors as I have used '#validation => TRUE' code to remove validation for that field(field_abc) – harshal Oct 10 '13 at 12:05
0

If you don't want to validate that field, then remove the following function

function test_mail1_validate($form, &$form_state) {



  if (!(is_numeric($form_state['input']['field_abc']))) {

    form_set_error('field_abc','ERROR');

  }
}

And remove the following line from test_mail1_form

$form['#validate'][] = 'test_mail1_validate';
-1

Are you asking for validation. If so please use this code, else explain your question clearly

function test_mail1_form($form, &$form_state) {
  $form = array();
      $form['field_abc'] = array(
        '#type' => 'textfield',
        '#title' => t('ABC'),
     );

      $form['submit-button'] = array(
        '#type' => 'submit',
        '#value' => t('sub'),
      );


      $form['#submit'][] = 'test_mail1_submit';
  return $form;
}

function test_mail1_submit($form, &$form_state) {
print_r($form);
exit;
}
  • please check the updated question . – harshal Oct 10 '13 at 13:13
  • Please check the Updated reply. – user21108 Oct 10 '13 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.