0

I'm trying to understand why when I call a form through drupal_get_form the submit part of it reload the page and if I don't call the form with drupal_get_form on that page again, it won't trigger the submits :(

function myFunction()
{
    if (isset($_POST['token'])) {
        return drupal_get_form('my_form');
    }

//why do I need to do that in order to get the submit form working?
    elseif($_POST['form_id']){
        return drupal_get_form('my_form');
    }
//why do I need to do that in order to get the submit form working?

    else drupal_goto('wherever');
}

In that case the first condition display my form but if I don't use that code below it won't trigger the submit form.

    elseif($_POST['form_id']){
        return drupal_get_form('my_form');
    }

The form is working fine, same goes for the submit, it's somehow related to that condition. I've got the feeling that because the submit is a button it will reload in order to get the form_submit but will fail to retrieve it as the condition is not working anymore. Does the drupal_retrieve_form would be more appropriate?

5
  • What are you trying to accomplish? Commented Nov 3, 2015 at 15:24
  • Just to get my form submit working without having to reuse return drupal_get_form('my_form');
    – GwenM
    Commented Nov 3, 2015 at 15:25
  • Could you post your hook_form() and hook_form_submit()? Commented Nov 3, 2015 at 15:34
  • It's not related to the form_submit as it's not even triggered and the form is just 2 submits, they will reload the page but do nothing else unless I use the drupal_get_form and then will trigger the correct submit_form. see above
    – GwenM
    Commented Nov 3, 2015 at 15:56
  • 1
    If you don't invoke drupal_get_form in the callback for the page submission, then the form won't be retrieved from cache, and no handlers will be executed @Namari. Read through the code for drupal_build_form() and it will all be clear. Yes, drupal_retrieve_form is an option if you're happy buildling it manually
    – Clive
    Commented Nov 3, 2015 at 16:15

0

Your Answer

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

Browse other questions tagged or ask your own question.