Reputation: 25
I've create a form like:
function create_custom_form($form, &$form_state) {
$form['#action'] = "#";
....
}
function create_custom_form_validate($form, &$form_state) {
....
}
function create_custom_form_submit($form, &$form_state) {
....
if(..)
drupal_goto('abc');
else
drupal_goto('xxx');
}
when i submit this form drupal before go to action and after read my function... how I can bypass the action-form and read only a _submit function?
Upvotes: 2
Views: 6036
Reputation: 171
Do not use drupal_goto as there may be more "submit" callbacks to execute. The drupal_goto function will interrupt these.
Instead, use the $form_state['redirect'] = ...
http://api.drupal.org/api/drupal/includes!form.inc/function/drupal_redirect_form/7
function create_custom_form_submit($form, &$form_state) {
....
if(..)
$form_state['redirect'] = 'abc';
else
$form_state['redirect'] = 'xxx';
}
As this function has the same form ID (create_custom_form
) - with the word "_submit" appended then this function will be executed automatically and so there is no need to add any submit callbacks into the form.
If you want an additional function to execute on submit then you should do as Hamza has suggested, only your additional function will have a different name. e.g.
function create_custom_form($form, &$form_state) {
$form['#action'] = "#";
....
// Add any additional callbacks to call before any redirects happen
$form['#submit'][] = 'create_custom_form_additional_submit_callback';
$form['#submit'][] = ...
}
function create_custom_form_additional_submit_callback($form, &$form_state) {
// Do something before redirect
...
}
In the above example:
create_custom_form_additional_submit_callback
AND
create_custom_form_submit
(because its got the same name with '_submit' appended)will execute and only when they have both finished will the redirect be executed.
Upvotes: 3