If a form field has the name 'edit'; e.g.:

$form['edit'] = array(
  '#type' => 'textfield',
  ...
);

then upon submitting the form we will be redirected to a "strange" URL: a URL which is the first letter typed into that form field. For example, if we type "rolex" into the field, then, after clicking the submit button, we will be redirected to http://example.com/r.

That's becaue drupal_goto(), which is used by FAPI, has the folowing code:

[...] if (isset($_REQUEST['edit']['destination'])) {

This condition will evaluate to TRUE. That's how string subscripts are handled in PHP. Another example:

$a['edit'] = 'rolex';
// the following statement prints 'r'
print $a['edit']['destination']; 

(Bug discovered while helping a user in the fourm.)

Comments

Crossfeed’s picture

Version: 5.x-dev » 6.15

same problem in D6, a form and all of its hooks can't be named edit. If they are called something with edit,

For example: modul_edit_form_submit() will redirect to the same "strange" url als reported above

changing the forms name to editor solves all failures

tamerzg’s picture

Version: 6.15 » 6.19

I just spent an hour figuring why my form is not redirecting properly. It ended up because one of the form fields was named 'edit'.

damien tournoud’s picture

Version: 6.19 » 6.x-dev

Someone wants to take a shot at rolling a patch? We need to add a is_array() here.

tamerzg’s picture

Status: Active » Needs review
StatusFileSize
new550 bytes

Yes, is_array should fix the problem.
Here is a patch.
--------------
Tamer Zoubi
Freelancer, Drupalist
Skype: tamerzg2005

tamerzg’s picture

Status: Needs review » Patch (to be ported)
albert volkman’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new590 bytes

D6 backport.

Status: Needs review » Needs work

The last submitted patch, form_fields_edit-212840-d6-6.patch, failed testing.

albert volkman’s picture

Status: Needs work » Needs review
StatusFileSize
new618 bytes

Ah, we need to check for the existence of $_REQUEST['edit'] first.

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.