Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I submit my Drupal form to any other internal page?
    text
    copied!<p>I'm having a problem with Drupal forms. Can't think of a way to solve it and I was wondering if any brain out there has the solution to my problem.</p> <p>I have this form:</p> <pre><code>&lt;?php function mymodule_myform(){ $form['#action'] = url('search/cards'); $form['whatwhere']['what'] = array( '#type' =&gt; 'textfield', '#title' =&gt; t('What?'), '#maxlength' =&gt; 80, '#required' =&gt; TRUE, ); $form['submit'] = array( '#type' =&gt; 'submit', '#value' =&gt; t('Search'), ); } ?&gt; </code></pre> <p>Which, as you can see, is supposed to submit all info to <code>www.example.com/search/cards</code>. This will indeed submit my form to the desired URL. However, without the <code>mymodule_menu()</code> hook defining the path, it will end in a 404.</p> <p>So I add:</p> <pre><code>&lt;?php function mymodule_menu(){ $items['search/%'] = array( 'title' =&gt; t('Search Results'), 'page callback' =&gt; 'mymodule_main', 'access arguments' =&gt; array('access content'), 'file' =&gt; 'mymodule.inc', ); } ?&gt; </code></pre> <p>And, at <code>mymodule.inc</code> file I'll create my function <code>mymodule_main()</code>:</p> <pre><code>&lt;?php function mymodule_main(){ print_r($_POST); die(); // ### Note the die(); ### return 'Just searched: '. $_POST['what']; } ?&gt; </code></pre> <p>If I leave it exactly like it is, of course PHP will end the script execution right after printing my form info on the screen. All good!</p> <p>However, if I remove the <code>die()</code>, it seems the function is called twice, and the second call does not have $_POST filled up anymore.. Seems <code>mymodule_menu()</code> overrides in some way whatever the form submit handler is doing... </p> <p>The question is: <strong>How can I submit my form to any other internal page without having the 404 and keep my form info?</strong></p> <p>Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload