Hi
I have a custom js file in my custom module, which generates a 3-digit ID,
function genRand() {
return Math.floor(Math.random()*899+100);
}
I would like to make this ID available in my webform, which I've created using the Webform 7.x-4.2 module.
My scenario is as such:
1. When a user opens a webform page, the js is loaded
2. The generated unique ID is passed automatically to the webform (preferably hidden from browser display)
3. When submitting the form, the ID is saved as well alongside the other data.
On a side note, will I get any issue with the user login form, since I do not want the ID to be loaded at any point in time there?
How can I achieve this?
Comments
You can use Hook_FORM_ID
You can use Hook_FORM_ID_ALTER for this purpose and attach your JS with desired form.
Can you be more explicit on
Can you be more explicit on how to do this? This is the first time am having to do something like this.
hook_form_alter
You can write something like below in hook_form_alter
Thanks,
Vijay Thummar
thanks
thanks
Is there a way to make the form id a dynamic one in the code?
this part:
if ($form_id == 'webform_client_form_<n>') {
The form id is generated by
The form id is generated by the webform automatically and you will have to trace that what is the id of your form.
Make configurable value
If you don't want to hard code webform_id then you can make that variable as a configurable value through variable table.
Use system settings form and use that variable in code.
Thanks,
Vijay Thummar
Can you pls provide me with
Can you pls provide me with an example of doing so?
Check below thread
Check below thread
https://www.drupal.org/node/206761
Thanks,
Vijay Thummar
Using Vijay's inline jquery,
Using Vijay's inline jquery, how can I modify it to accept DDMMYYYY values before the random number? I tried adding a simple string value infront but got an error when running the code.
Write something like
Write something like
Thanks,
Vijay Thummar
I've tried the new code,
I've tried the new code, replacing the element id with mine, but am getting a blank value when inspecting with firebug:
<input id="form-gen-id" type="hidden" value="" name="Generated ID">