I have a form that is built in my custom module.
when setting the form I do the following things:
$form['#ajax'] = array('enabled' => TRUE,);
and for the submit button I do this:
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
'#ajax' => array('submitter' => TRUE),
);
My form renders correctly on the front end and when I hit the submit button, the button changes to say "Loading..." but I can see the browser is starting to redirect. The module submit functions fire appropriatly (as my database gets written to) but then the browser redirects to the same page it was already on. only the page is just white with a textarea on it with a load of array entries being spat out.
{ "status": true, "updaters": [ ], "debug": [ ], "messages_error": [ ], "messages_status": [ ], "messages_warning": [ ], "redirect": null, "preview": null, "form_id": "custommodule_myform", "options": { "enabled": true } }
I've seen similar issues being registered for this happening with webforms, but not seen anyone saying this is happening when trying to convert forms via code.
If anyone can help that would be awesome as my deadline is approaching fast!
Thanks in advance!
Ad
Comments
Comment #1
adam_bush commentedI've managed to get this to stop happening, however I now for the life of me cannot figure out how to use code to stop this redirecting... I've placed an echo in ajax.module to check that it is running and it prints out just fine, however after the button changes to "Loading..." the page refreshes (though all of the the form submission stuff runs properly - so my flags are set and data is written to the db)
Is there anything I need to do in particular to tell a form not to redirect... i can see how to do it using ajax ui... but I need to do it for coded forms.
Many thanks
Adam
Comment #2
dooug commentedAdam,
Did you make any progress on this? I am running into similar issues with a form for the Signup module that is embedded into a view with the Views_embed_form module.
I've tried to make sense of the instructions below from the documentation. But they are somewhat unclear on what to set the #action to.
Comment #3
bsenftner commentedI tried setting '#action' to the url of the page, and it seems to work... no idea if that is correct.
Comment #4
ludo.rI aslo get a blank page with a textarea filled with json code.
I just enabled this, in my custom module and custom form :
I guess this is not the expected behaviour.
Am I missing something?
Comment #5
ludo.r