Hi:
Thank you so much for giving us this wonderful module.
I run into a little issue, please help me a little bit.
I have a site which allow normal users to create a node attached to a webform.
I don't want them to see the template selection field, so I hide it and set the '#default_value' => '1'.
It works fine when users create a node, but when user edit the node, the Webform Submission access checkbox will become empty instead of the one I had. If I set the template selection to none, it will not overwrite the Submission access.
Is there a way that I add add a little code before I set '#default_value' => '1'
Something like If (add new) '#default_value' => '1'; elseif (edit) '#default_value' => '0'
Thank you very much~!
Comments
Comment #1
rv0 CreditAttribution: rv0 commentedThere is some functionality in the module that will help you with hiding the selection field.. It's not very flexible, but it works:
From webform_template.api.php:
Below this code adapted to your usecase
Replace YOURMODULE by whatever name you gave your module.
Another approach will work too, but this seems most elegant.
You can also use the if (isset($form['#node']->nid)) { in your current form_alter code (that is where you are setting the default, right?)
Comment #2
jams1988 CreditAttribution: jams1988 commentedThank you rv0:
My problem is not hiding the form, it is to set different default_value of template selections.
Sorry, I am using the 7.12, not the dev version.
When user create a node, the default_value is 1
when user edit a node, default_value is 0
There the code I try in webform_template.module:
It didn't work because the if statement didn't go through..
Thanks for the quick reply......
The reason why I want to change the default_value is that if it is '0' wheh user edit a node, it will not trigger the
db_delete('webform')->condition('nid', $node->nid)->execute();
db_delete('webform_component')->condition('nid', $node->nid)->execute();
db_delete('webform_emails')->condition('nid', $node->nid)->execute();
db_delete('webform_roles')->condition('nid', $node->nid)->execute();
db_delete('webform_submissions')->condition('nid', $node->nid)->execute();
db_delete('webform_submitted_data')->condition('nid', $node->nid)->execute();
And it will still keep the webform attributes of the node, but change the node itself....
Comment #3
rv0 CreditAttribution: rv0 commented@jams1988
never change the module code itself unless you plan on extending the functionality/providing a patch
The code you have there cannot work for many reasons (no $op variable, syntax errors, ..)
Make a custom module (there's plenty of info on how to do that on this site)
Use hook_form_alter to modify the #default_value property
The module will need a higher "module weight" to make sure it runs after webform_template, to do this see the code in webform_template.install.php
Alternatively, someone could write a patch for webform_template to add a config screen to the template field, where setting a default value is made possible. I currently dont have the time/need to provide this, but will review any patches for this.
Comment #4
rv0 CreditAttribution: rv0 commented@jams1988
never change the module code itself unless you plan on extending the functionality/providing a patch
The code you have there cannot work for many reasons (no $op variable, syntax errors, ..)
Make a custom module (there's plenty of info on how to do that on this site)
Use hook_form_alter to modify the #default_value property
The module will need a higher "module weight" to make sure it runs after webform_template, to do this see the code in webform_template.install.php
Alternatively, someone could write a patch for webform_template to add a config screen to the template field, where setting a default value is made possible. I currently dont have the time/need to provide this, but will review any patches for this.
Comment #5
rv0 CreditAttribution: rv0 commented@jams1988
never change the module code itself unless you plan on extending the functionality/providing a patch
The code you have there cannot work for many reasons (no $op variable, syntax errors, ..)
Make a custom module (there's plenty of info on how to do that on this site)
Use hook_form_alter to modify the #default_value property
The module will need a higher "module weight" to make sure it runs after webform_template, to do this see the code in webform_template.install.php
Alternatively, someone could write a patch for webform_template to add a config screen to the template field, where setting a default value is made possible. I currently dont have the time/need to provide this, but will review any patches for this.
Comment #6.0
(not verified) CreditAttribution: commentedlittle more