Hello,
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.
I have this form:
<?php
function mymodule_myform(){
$form['#action'] = url('search/cards');
$form['whatwhere']['what'] = array(
'#type' => 'textfield',
'#title' => t('What?'),
'#maxlength' => 80,
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Search'),
);
}
?>
Which, as you can see, is supposed to submit all info to www.example.com/search/cards
.
This will indeed submit my form to the desired URL. However, without the mymodule_menu()
hook defining the path, it will end in a 404.
So I add:
<?php
function mymodule_menu(){
$items['search/%'] = array(
'title' => t('Search Results'),
'page callback' => 'mymodule_main',
'access arguments' => array('access content'),
'file' => 'mymodule.inc',
);
}
?>
And, at mymodule.inc
file I'll create my function mymodule_main()
:
<?php
function mymodule_main(){
print_r($_POST);
die(); // ### Note the die(); ###
return 'Just searched: '. $_POST['what'];
}
?>
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!
However, if I remove the die()
, it seems the function is called twice, and the second call does not have $_POST filled up anymore.. Seems mymodule_menu()
overrides in some way whatever the form submit handler is doing...
The question is: How can I submit my form to any other internal page without having the 404 and keep my form info?
Thanks in advance.