1

I am developing a form. 2 functions are:

function reserve_multi_step_form($form, &$form_state)
{
       $module_path = drupal_get_path('module', 'reserve');

       $form['#theme'] = 'reserve_form_2';
       $form["agreed"] = array(
                            '#type' => 'checkbox',
                            '#title' => t("I accept the deposit policy"),
                            '#attributes' => array("onChange" => "policy_accepted();"),
                            );


       $form['submit'] = array(
                       '#type' => 'submit',
                       '#value' => t('Submit'),
                       '#attributes' => array('style' => "padding: 0 10px;"),
                       "#disabled" => true,
                       );

       return $form;
    }

function reserve_multi_step_form_submit($form, &$form_state) {
       print 1111;exit;
}

The theme function:

function reserve_theme($existing, $type, $theme, $path){
   return array(
                'reserve_form_2' => array(
                                          'render element' => 'form',
                                          'template' => 'reserve_form_2',
                                          'path' => drupal_get_path('module', 'reserve'),
                                          ),
}

In the template file I print some text and render the form:

    <?php
    print "text";
    print drupal_render_children($variables["form"]);

The form is displayed correctly. But after I click submit button, the reserve_multi_step_form_submit is not called. Without theming it works. What can be an issue?

1 Answer 1

1

You have the #disabled property set on your submit element. Drupal's form API does not process the input for any element, including submit buttons, if the #disabled property is set on the server side.

If you're interested in the code behind this, the decisions are made in the _form_builder_handle_input_element() function in the includes/form.inc file of your Drupal installation.

If you want the submit button to be disabled by default for client-side purposes (i.e. you'll be enabling it through JS based on some action taken by the user) you would be better off setting the disabled attribute directly on the element, as Drupal pays no attention to this when processing the form:

$form['submit'] = array(
  '#type' => 'submit',
  '#value' => t('Submit'),
  '#attributes' => array(
    'style' => "padding: 0 10px;",
    'disabled' => 'disabled'
  )
);

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.