2

I have a 9 page form (content type). In the first page I have a text field which is configured to be required. When this field is empty, and I hit the Next Step button to go the 2nd page of the form, I do not get any validation error. If I come back to the first page by clicking Previous Step button and then click the Next Step I get the required field validation error. I am wondering why I don't get the validation error when I click the Net Step button on the 1st form page where I have the text field that requires data.

Hope someone knows the answer to this problem. Thanks.

Here is my custom module code:

  function ueb_package_build_request_helper_form_alter(&$form, &$form_state, $form_id) {
      if ($form_id == 'ueb_model_package_build_request_node_form') {
        $form['#validate'] = array('ueb_package_build_request_helper_form_validate');
        $form['#submit'] = array('ueb_package_build_request_helper_form_submit');
        $form['field_build_request_note']['und']['0']['value']['#attributes']['readonly'] = TRUE;

       // set the simulation start and end date
       $form['field_start_date']['und']['0']['#default_value']['value'] = '01/01/2011';
       $form['field_start_date']['und']['0']['#default_value']['value2'] = '12/31/2011';
      }
   }

    function ueb_package_build_request_helper_form_validate($form, $form_state) {
      $node_content_type = 'ueb_model_package_build_request';
      $step = $form_state['storage']['field_group_ajaxified_multipage_step'];
      //dpm($form_state);

     if($step == 1) {
       // validate the simulation start and end date
       // make sure this date is the calendar year 2011
       $start_date = $form_state['values']['field_start_date']['und'][0]['value'];
       $end_date = $form_state['values']['field_start_date']['und'][0]['value2'];
       $start_date_parts = date_parse($start_date);
       $end_date_parts = date_parse($end_date);
       if($start_date_parts['year'] !=2011) {
        form_set_error('Simulation start date', t('Start year must be 2011.'));        
       }
     if($end_date_parts['year'] !=2011) {
       form_set_error('Simulation end date', t('End year must be 2011.'));
     }

  }

    function ueb_package_build_request_helper_form_submit($form, &$form_state) {
      drupal_set_message(t('Your request to build a package has been received.'), 'status');
   }
3
  • Are you using a contributed module or custom form? – Aboodred1 May 23 '13 at 0:53
  • I am not sure I fully understand your question. I am quite new to Drupal. This problem I am getting is with a new content type that I have created. All the fields I have added to this content type through UI. However, I have a created a new module that implements the hook_form_alter() to set some fields to readonly and a custom validation function to validate this content type when the user saves a new content of this content type. Initially I thought my custom validation might be a problem. I commented out the custom validation but it didn't make any difference to the problem I am having. – user1380140 May 23 '13 at 15:02
  • can you post your code with your question! – Aboodred1 May 23 '13 at 15:28

Your Answer

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

Browse other questions tagged or ask your own question.