I'm trying to figure out the magic of a multipart form.
I'm trying to have a user register his family. So he goes to a form which has a blank for one person and he keeps clicking "Add another person" until he has enough blanks for all his family members at which point he can hit "Save" and it's processed.
Currently I'm doing this in form_validate. If they clicked the Add Another Person button I called form_set_error('',''). Which returns them to the form w/o giving them an error. All the form data is still filled in. If the click the Save button I validate and return and form_submit() is called which saved the data.
I'm trying to figure out how to pass hidden data so that it can't be tampered with (For example a family id). Initially I was using a hidden field with a #value (as opposed to #default_value) under the assumption that Drupal would validate the field for me and ensure it was not changed. This doesn't seem to be the case and I'm trying to figure out another way to keep data with my form w/o having it tampered with. I tried using a field of #type 'value', but that didn't seem to get passed back into with the $form_state for the next iteration. A couple of thoughts I had.
1. Validate the hidden data myself in the validate function comparing $form_state and $form. 2. Change the way I'm doing this to a more drupal approved way so that it will validate my hidden data for me? (Is there a flag I can set) 3. Figure out how to get value fields passed between form submissions.
Thanks, David
This would be a good candidate for AHAH. Take a look at poll.module, which pretty much does what you're asking for adding additional choices to the poll.
Jamie Holly http://www.intoxination.net http://www.hollyit.net
On 1/15/2010 1:16 AM, David Spindler wrote:
I'm trying to figure out the magic of a multipart form.
I'm trying to have a user register his family. So he goes to a form which has a blank for one person and he keeps clicking "Add another person" until he has enough blanks for all his family members at which point he can hit "Save" and it's processed.
Currently I'm doing this in form_validate. If they clicked the Add Another Person button I called form_set_error('',''). Which returns them to the form w/o giving them an error. All the form data is still filled in. If the click the Save button I validate and return and form_submit() is called which saved the data.
I'm trying to figure out how to pass hidden data so that it can't be tampered with (For example a family id). Initially I was using a hidden field with a #value (as opposed to #default_value) under the assumption that Drupal would validate the field for me and ensure it was not changed. This doesn't seem to be the case and I'm trying to figure out another way to keep data with my form w/o having it tampered with. I tried using a field of #type 'value', but that didn't seem to get passed back into with the $form_state for the next iteration. A couple of thoughts I had.
- Validate the hidden data myself in the validate function comparing
$form_state and $form. 2. Change the way I'm doing this to a more drupal approved way so that it will validate my hidden data for me? (Is there a flag I can set) 3. Figure out how to get value fields passed between form submissions.
Thanks, David
You are doing 'multistep' and not 'multipart' right?
If so, you have to, every time you submit an interation of your form, copy all values you want to keep in the $form_state['storage'] and set the $form_state['rebuild'] to TRUE.
On last submission (last iteration), set back the $form_state['rebuild] to FALSE, and use the values you stored in $form_state['storage'] to do you real submission.
Values in the $form_state['storage'] are stored in the form cache until the form has been really submitted (i.e. until it passed a submission with the $form_state['rebuild'] to FALSE.
Hope it helps. Pierre.
#type=> value should show up in your validate functions as submitted data in $form_state['values'].
From the #type=>value forms reference:
Note that as of Drupal 6, you can also simply store arbitrary variables in $form['#foo'] instead, as long as '#foo' does not conflict with any other internal property of the Form API.
You really should be able to do this, just make sure its not objects, but structured data should work.
Dave
-----Original Message----- From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of David Spindler Sent: Thursday, January 14, 2010 10:17 PM To: support@drupal.org Subject: [support] Multipart Form in 6.x
I'm trying to figure out the magic of a multipart form.
I'm trying to have a user register his family. So he goes to a form which has a blank for one person and he keeps clicking "Add another person" until he has enough blanks for all his family members at which point he can hit "Save" and it's processed.
Currently I'm doing this in form_validate. If they clicked the Add Another Person button I called form_set_error('',''). Which returns them to the form w/o giving them an error. All the form data is still filled in. If the click the Save button I validate and return and form_submit() is called which saved the data.
I'm trying to figure out how to pass hidden data so that it can't be tampered with (For example a family id). Initially I was using a hidden field with a #value (as opposed to #default_value) under the assumption that Drupal would validate the field for me and ensure it was not changed. This doesn't seem to be the case and I'm trying to figure out another way to keep data with my form w/o having it tampered with. I tried using a field of #type 'value', but that didn't seem to get passed back into with the $form_state for the next iteration. A couple of thoughts I had.
1. Validate the hidden data myself in the validate function comparing $form_state and $form. 2. Change the way I'm doing this to a more drupal approved way so that it will validate my hidden data for me? (Is there a flag I can set) 3. Figure out how to get value fields passed between form submissions.
Thanks, David -- [ Drupal support list | http://lists.drupal.org/ ]
The problem isn't that it's now showing up in my validate function, it's that when validate returns an error it's not showing back up in the form function.
IE. 1.form (load from database with #default_values) 2. The click "Add button" 3.form_validate (They hit the "add" button so we set form_error('','')) 4.form (data is now not loaded from the database but is populated with the users entries automatically (b/c we used default values) 5. Go back to #2 until they click the "Save" button 6. form_validate(They hit the save button so really do a validate and set errors) 7. form_submit
This works really well, I don't have to copy anything, but my hidden forms are subject to editing along with all my other data and 'value' fields might make it to the form_validate function, but when it sets the error and bounces them back to the form the values are lost.
On Fri, Jan 15, 2010 at 10:07 AM, Metzler, David metzlerd@evergreen.edu wrote:
#type=> value should show up in your validate functions as submitted data in $form_state['values'].
From the #type=>value forms reference:
Note that as of Drupal 6, you can also simply store arbitrary variables in $form['#foo'] instead, as long as '#foo' does not conflict with any other internal property of the Form API.
You really should be able to do this, just make sure its not objects, but structured data should work.
Dave
-----Original Message----- From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of David Spindler Sent: Thursday, January 14, 2010 10:17 PM To: support@drupal.org Subject: [support] Multipart Form in 6.x
I'm trying to figure out the magic of a multipart form.
I'm trying to have a user register his family. So he goes to a form which has a blank for one person and he keeps clicking "Add another person" until he has enough blanks for all his family members at which point he can hit "Save" and it's processed.
Currently I'm doing this in form_validate. If they clicked the Add Another Person button I called form_set_error('',''). Which returns them to the form w/o giving them an error. All the form data is still filled in. If the click the Save button I validate and return and form_submit() is called which saved the data.
I'm trying to figure out how to pass hidden data so that it can't be tampered with (For example a family id). Initially I was using a hidden field with a #value (as opposed to #default_value) under the assumption that Drupal would validate the field for me and ensure it was not changed. This doesn't seem to be the case and I'm trying to figure out another way to keep data with my form w/o having it tampered with. I tried using a field of #type 'value', but that didn't seem to get passed back into with the $form_state for the next iteration. A couple of thoughts I had.
- Validate the hidden data myself in the validate function comparing
$form_state and $form. 2. Change the way I'm doing this to a more drupal approved way so that it will validate my hidden data for me? (Is there a flag I can set) 3. Figure out how to get value fields passed between form submissions.
Thanks, David
[ Drupal support list | http://lists.drupal.org/ ]
[ Drupal support list | http://lists.drupal.org/ ]