By modou33 on
Hi everybody,
I'm developping a module for managing a form. I need to stay in the same page after submitting (for triggering with a js). But when i use $form_state['redirect'] = FALSE; (in every function), the process is executed two time. For example, i use form submit like this:
function commande_express_form_submit($form, &$form_state) {
$form_state['redirect'] = FALSE;
db_insert('commande_express')
->fields(
array(
'date' => date('Y-m-d__H:i:s'),
'nom' => $form_state['values']['name'],
'telephone' => $form_state['values']['phone'],
'dispo' => $form_state['values']['dispo']
)
)->execute();
drupal_add_js('jQuery(document).ready(function () { alert("Hello!"); });', 'inline');
}
I don't know why but with this code, db_insert is executed two time, and there is two same line in my database. And then the drupal_add_js is executed two time too and i get two alert("Hello") in my browser.
Thanks you for you help.
Comments
Does the double submittion
Does the double submittion happen even without $form_state['redirect'] = FALSE;
No, the code is submitted one
No, the code is submitted one time when i usen't the $form_state['redirect']=FALSE and all work nice.
For every hook function, when i call a $form_state['redirect'], the code in the hook is called two times. For exemple:
I got two echo alert with this code.
Did you mean you were
Did you mean you were triggering the form submit with JS. If so, do you have the code for that?
My form is processed by
My form is processed by drupal classic system, but after the end of submit process, i just need to stay in the same page for updating some block.
here is all my code in
here is all my code in commande_express.module