DrupalBin
Submit Code
About
Recent Posts
Code
Fix for Fix for Code
Fix for Code
Code
Node type whitelist
an axe coach accessories
coach purses married
Fix for de las ghd alturas
de las ghd alturas
Code
more
User login
Log in using OpenID:
What is OpenID?
Username:
*
Password:
*
Log in using OpenID
Cancel OpenID login
Create new account
Request new password
Tags
CCK
drupal
fapi
jquery
menu
module
php
simpletest
taxonomy
test
theme
views
more tags
Home
Fix for AHAH in core: edge case
View
Fix
February 14, 2009 - 11:30am —
Wim Leers
// If the form is being rebuilt due to something else than a pressed button,
// e.g. a select that was changed, then $_POST['op'] will be empty. As a
// result, Forms API won't be able to detect any pressed buttons. Eventually
// it will call _form_builder_ie_cleanup(), which will automatically, yet
// inappropriately assign the first in the form as the clicked button. The
// reasoning is that since the form has been submitted, a button surely must
// have been clicked. This is of course an invalid reasoning in the context
// of AHAH forms.
// To work around this, we *always* set $form_state['submitted'] to true,
// this will prevent _form_builder_ie_cleanup() from assigning a wrong
// button. When a button is pressed (thus $_POST['op'] is set), then this
// button will still set $form_state['submitted'],
// $form_state['submit_handlers'] and $form_state['validate_handlers'].
// This problem does not exist when AHAH is disabled, because then the
// assumption is true, and then you generally provide a button as an
// alternative to the AHAH behavior.
$form_state
[
'submitted'
]
=
TRUE
;
// Continued from the above: when an AHAH update of the form is triggered
// without using a button, you generally don't want any validation to kick
// in. A typical example is adding new fields, possibly even required ones.
// You don't want errors to be thrown at the user until they actually submit
// their values. (Well, actually you want to be smart about this: sometimes
// you do want instant validation, but that's an even bigger pain to solve
// here so I'll leave that for later…)
if
(
!
isset
(
$_POST
[
'op'
]
)
)
{
// For the default "{$form_id}_validate" and "{$form_id}_submit" handlers.
$form
[
'#validate'
]
=
NULL
;
$form
[
'#submit'
]
=
NULL
;
// For customly set #validate and #submit handlers.
$form_state
[
'submit_handlers'
]
=
NULL
;
$form_state
[
'validate_handlers'
]
=
NULL
;
// Disable #required and #element_validate validation.
_ahah_helper_disable_validation
(
$form
)
;
}
ahah
Submit Fix
Summary:
Tags:
Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Show summary in full view
// If the form is being rebuilt due to something else than a pressed button, // e.g. a select that was changed, then $_POST['op'] will be empty. As a // result, Forms API won't be able to detect any pressed buttons. Eventually // it will call _form_builder_ie_cleanup(), which will automatically, yet // inappropriately assign the first in the form as the clicked button. The // reasoning is that since the form has been submitted, a button surely must // have been clicked. This is of course an invalid reasoning in the context // of AHAH forms. // To work around this, we *always* set $form_state['submitted'] to true, // this will prevent _form_builder_ie_cleanup() from assigning a wrong // button. When a button is pressed (thus $_POST['op'] is set), then this // button will still set $form_state['submitted'], // $form_state['submit_handlers'] and $form_state['validate_handlers']. // This problem does not exist when AHAH is disabled, because then the // assumption is true, and then you generally provide a button as an // alternative to the AHAH behavior. $form_state['submitted'] = TRUE; // Continued from the above: when an AHAH update of the form is triggered // without using a button, you generally don't want any validation to kick // in. A typical example is adding new fields, possibly even required ones. // You don't want errors to be thrown at the user until they actually submit // their values. (Well, actually you want to be smart about this: sometimes // you do want instant validation, but that's an even bigger pain to solve // here so I'll leave that for later…) if (!isset($_POST['op'])) { // For the default "{$form_id}_validate" and "{$form_id}_submit" handlers. $form['#validate'] = NULL; $form['#submit'] = NULL; // For customly set #validate and #submit handlers. $form_state['submit_handlers'] = NULL; $form_state['validate_handlers'] = NULL; // Disable #required and #element_validate validation. _ahah_helper_disable_validation($form); }
Syntax highlighting mode:
ActionScript
ColdFusion
Diff
Drupal 5
Drupal 6
HTML
INI
Javascript
MySQL
PHP
Python
robots.txt
SQL
Text
Select the syntax highlighting mode to use.
See Also:
Order
Title:
URL:
-1
0
1
Title:
URL:
-1
0
1
Any links you'd like to have associated with the post (Drupal.org issue, Wikipedia article, etc).
File attachments
Changes made to the attachments are not permanent until you save this post. The first "listed" file will be included in RSS feeds.
Attach new file:
The maximum upload size is
1 MB
. Only files with the following extensions may be uploaded:
jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp phps
.