| Project: | AHAH helper |
| Version: | 6.x-2.0 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
Hi,
Thanks for this great module. I have a created a multi-step form using a custom module. I use the multiple steps to refine/add new elements to the form. Every thing works as expected, except my final post data is not coming to the submit function in $form_state['values'].
Instead i get the post data submitted during the previous ahah call. I did some debugging of the form submission. It seems to be because of caching the form array already built by form_builder(). When we send the form array to form_builder function, it gets the value from post and creates "#value" property in the elements of the $form array.
function ahah_helper_render($form_item_to_render = FALSE) {
.......
// We *do* save the form to the cache, so modules that use "D6 core style"
// AHAH updates still work.
form_set_cache($form_build_id, $form, $form_state);
......
}This code snippet above shows the place where this built array gets stored in the cache.
When the user submits the form normally (Final step of form - after all the ahah calls), the form_bulder() keeps the "#value" property in the elements instead of mapping it from the post.
So the changes made to the form (by the user) before the final submit never gets submitted. However when i comment the above mentioned line, The submission of the form works as expected.
Also with java script disabled, the form works as intended.
Please bear with me, if any of my analysis is wrong.
Thanks
Comments
#1
I have similar problem with form-state[values].
I'm using hook_form_alter in the user registration form. The code is based on sample in http://drupal.org/node/328201#comment-1116930
<?phpfunction mymodule_form_alter(&$form, $form_state, $form_id) {
switch($form_id) {
case 'user_register':
// ISSUE 1: Registration of ahah_helper
// Register the entended form for ahah_helper behaviour
ahah_helper_register($form, $form_state);
// ISSUE 2: content cannot be saved by another user
/**
* @TODO: Figure out the main cause why this happens. It has something
* to do with staying on the node form instead of redirecting to the view.
*/
$form['changed']['#default_value'] = $_SERVER['REQUEST_TIME'];
//my alter function
mymodule_user_register_alter($form, $form_state);
break;
...
}
?>
In the function mymodule_user_register_alter($form, $form_state) I put 2 fields with #ahah, similar to 'company' sample. The submitting values work only in some cases:
If there is a validation error at the first submit, the form_state[values] these ahah fields are lost. But in a second submit with validation error (re-filling the form at the second time), form_state[values] will show the typed values.
But more interesting, is that in the first time the form is shown , when the ahah gets activated (throwing event and updating the form), some fields with not-filled values at this point will lose any value at submit, too.
For example, I use the legal module. It puts a checkbox in the registration form that must be checked.
If I check-on the "I accept terms & conditions" before any change on ahah field (updating the form), the submit works. But if i check after, It gets "you must check" validation error. The checked value is lost in form_state[values].
I tried to comment the line form_set_cache($form_build_id, $form, $form_state) in function ahah_helper_render(...), but it does not work or cause some other problems.
¿Any help?
#2
Please update to version 2 and check if this problem persists.
#3
I can't get this to work with 2.0 version.
An error occurred.
/drupal/ahah_helper/billing_info
<br />
<b>Fatal error</b>: require_once() [<a href='function.require'>function.require</a>]: Failed opening required '' (include_path='.;C:\xampp\php\pear\') in <b>C:\xampp\htdocs\drupal\sites\all\modules\ahah_helper\ahah_helper.module</b> on line <b>145</b><br />
I then replaced the code in line 146 '#file' with 'file':
if (isset($form_state['storage']['#ahah_helper']['file'])) {
require_once($form_state['storage']['#ahah_helper']['#file']);
}
And it seems to work now.
#4
Ugh. Stupid bug then… I guess the example module still works because that part of ahah_helper is not triggered by it, which is why I didn't notice it. Would you mind rolling a proper patch? :)
But it works for you now, excellent, one bug less! :)
#5
Now I have another problem.
I put a validate callback in mymodule_form_alter:
...$form['#validate'][] = 'mymodule_user_register_validate';
...
The validate func contains:
function mymodule_user_register_validate($form, &$form_state) {$value = $form_state['storage']['groupx']['field1'];
$form_state['storage']['field_cck'][0]['value'] = $value;
return;
}
I do this because I need to store the value in a cck field.
I tried using 'storage' array, and 'values' array.
In any case, the function is called, and the values are stored (I checked), but the cck field is empty after submit.
Any ideas...?
I'll put a patch after this post is replied (I never did before).
#6
Patch attached.
msoler75: Any chance your bug is related to #375582: Data being overwritten in $form_state['storage'] due to array_smart_merge() when #multiple = TRUE?
#7
Forgot to change status.
#8
Patch fixes the bug. Looks like its ready to be committed.
#9
C'mon. It's a typo. Can we get this committed? I'm hoping to use this with Ubercart.
#10
Honestly, this is such a small thing, but still so critical, you should really have this committed and have a release packaged.
It's working now for me, so its not a big deal per say, but I tend to forget when I've made core/3rdparty-module hacks.
#11
This was already fixed time ago. Still in 6.x-2.x btw.
#12
Automatically closed -- issue fixed for 2 weeks with no activity.