0

I was generating a simple form with below fields, but i am wandering why my field values are not storing in the $formstate['values'], but its in the $formstate['input'].. please have look into below code and correct me if i am doing something wrong.

function create_entry_form($form, &$form_state){
    $form['entry']['password'] = array(
      '#type' => 'password',
      '#required' => TRUE,
      '#default_value' => '',
      '#maxlength' => 15,
    );

    $form['entry']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('OK'),
      '#weight' => 100,
    );
    $form['entry']['emailid'] = array(
      '#type' => 'textfield',
      '#required' => TRUE,
      '#default_value' => '',
      '#maxlength' => 25,
    );

    $form['entry']['reqbtn'] = array(
      '#type' => 'button',
      '#value' => t('Request'),
      '#weight' => 106,
      '#executes_submit_callback' => TRUE,
      '#submit' => array('request_site_password'),
      '#limit_validation_errors' => array(),
    );

  return $form;  
}
function request_site_password($form, &$form_state) {
    echo '<pre>';print_r($form_state);exit;
  }
1
  • 1
    just curious, it appears you are building a custom password retrieval... why not use Drupal's and why use a custom submit function rather than Drupal's built in submit handler (which would have been create_entry_form_submit)? Commented Jun 1, 2018 at 6:18

1 Answer 1

1

If you want to get $formstate['values'] or $form_state['input'] values .You have to write like below.

    function create_entry_form($form, &$form_state){
        $form['entry']['password'] = array(
          '#type' => 'password',
          '#required' => TRUE,
          '#default_value' => '',
          '#maxlength' => 15,
        );

        $form['entry']['submit'] = array(
          '#type' => 'submit',
          '#value' => t('OK'),
          '#weight' => 100,
        );
        $form['entry']['emailid'] = array(
          '#type' => 'textfield',
          '#required' => TRUE,
          '#default_value' => '',
          '#maxlength' => 25,
        );

        $form['entry']['reqbtn'] = array(
          '#type' => 'submit',
          '#value' => t('Request'),
          '#weight' => 106,
          '#submit' => array('request_site_password'),
          );



      return $form;  
    }
   function request_site_password(&$form, &$form_state) {
    drupal_set_message('<pre>' . print_r($form_state['input'], TRUE) . '</pre>');
  }

You missed '&$form' in this function request_site_password(&$form, &$form_state)

2
  • The question is about why the values are empty but the input is not, not how to get it.
    – Kevin
    Commented May 31, 2018 at 4:26
  • I have changed the code based on your comment now you can get the values
    – sivani
    Commented May 31, 2018 at 4:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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