Wrong implementations of forms _submit() functions.

roychri - July 16, 2009 - 14:41
Project:MySite
Version:5.x-3.3
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Description

As per the forms api quick start guide, a _submit function should return the url to be redirected to and not use drupal_goto directly.

http://api.drupal.org/api/file/developer/topics/forms_api.html/5
Look under the section labeled "Submitting Forms", bullet number 4:

The return value of the _submit function will be the target of a drupal_goto; every form is redirected after a submit. If you return nothing, the form will simply be redirected to itself after a submit.

Wrong:

<?php
function myform_submit($form, $form_values) {
 
// do your thing
 
drupal_goto('somwhere');
}
?>

Good:

<?php
function myform_submit($form, $form_values) {
 
// do your thing
 
return 'somwhere';
}
?>

There are various forms _submit() function in the mysite module which are calling drupal_goto() instead of returning.
This means that I cannot use hook_form_alter() and override the destination by altering $form['#redirect'] like I am supposed to.
http://api.drupal.org/api/file/developer/topics/forms_api_reference.html...

#1

roychri - July 16, 2009 - 14:44
Status:active» needs review

Here is proposed patch

AttachmentSize
521246.patch 2.6 KB

#2

agentrickard - July 16, 2009 - 15:35

Looks good. Does it break anything?

#3

roychri - July 16, 2009 - 19:31

I did not take the time to do full suite of tests.
Does it even have a suite of unit test for d5?

#4

agentrickard - July 16, 2009 - 21:48

Good old fashioned form clicking is the only way to go. The only thing I could see breaking is the fake multi-step form stuff in edit and settings, but I don't see that affected here.

Those gotos(), btw, are a legacy of 4.7.x, I think.

#5

agentrickard - July 16, 2009 - 21:53
Status:needs review» reviewed & tested by the community

Looks good. I will roll a new release.

#6

agentrickard - July 16, 2009 - 21:54
Status:reviewed & tested by the community» needs work

Actually, there are instances of these all over the Type includes as well.

#7

agentrickard - July 16, 2009 - 21:58
Status:needs work» needs review

Here's an extended patch. One good review and I'll roll a new realease.

AttachmentSize
521246-extended.patch 6.98 KB
 
 

Drupal is a registered trademark of Dries Buytaert.