We are planning to use webforms for an online school admission form. The school will issue physical forms at the school and also offer the option to fill up the form online for those who wish. The physical forms have a Form number 1,2,3,4.....100. I need the online form to also have a form number that is auto-generated from 101 ...to 200. The form number is important for paying the fee.

1. Is there any way I can do this with webform?

2. I need the re-directed url to point to a printable version of the form so that parents can print or save the form for their records. How can I do this with webform. On local host I tried http://localhost/drupal5/?q=print/206 but I get re-directed to the form without any fields.

Any help will be highly appreciated.

Comments

gmasky’s picture

Title: Auto-generate From numbers as a field » Auto-generate Form numbers as a field

Sorry that should read Auto-generate Form numbers as a field

gmasky’s picture

Title: Auto-generate Form numbers as a field » Anyone Out there ??

Can anyone give me a yes or know answer if this is doable with the webform module or if there is another way to do this.

Thanx

quicksketch’s picture

Title: Anyone Out there ?? » Auto-generate Form numbers as a field

Yes it is possible but it requires use of the Additional processing field. Please keep your pants on when asking for free support on your free software.

1. Make a hidden field for "Registration number", don't give it any default value. Pay attention to the "Component ID" given to this new field. It's in the URL: node/x/edit/components/y. Where "y" is the Component ID. Also note the "Field key" for the component under the "Advanced" fieldset. It'll be a safe name like "registration_number".
2. In the main configuration for the Webform, under "Webform advanced settings" fieldset, enter some code similar to this in your "Additional processing" field:

$cid = 10; // Change to whatever the component ID is of your registration number field.
$key = 'registration_number'; // Change to whatever the component field key is.
$starting_number = 100; // Change to whatever you want webform submission numbers to start from.
$count = db_result(db_query('SELECT COUNT(*) FROM {webform_submissions} WHERE nid = %d', $node->nid));

// The 'submitted' value needs to be updated to save to the database.
$form_values['submitted'][$cid] = $starting_number + $count;
// The 'submitted_tree' value needs to be update to include in the sent e-mails.
$form_values['submitted_tree'][$key] = $starting_number + $count;

You can find other examples of using the additional processing field in the Webform handbook: http://drupal.org/handbook/modules/webform

gmasky’s picture

Thanks Nathan,

I will try this out.

BTW, I am not doing this for money. I am trying to get 120 schools in India to switch to Drupal and it seems the Webform module will play an important part in this.

Now only If I can get the return url to display a PDF format of the form for printing on a legal sized paper :)

...just another Drupal evangelist

quicksketch’s picture

Status: Active » Closed (fixed)

Closing after lack of activity.

crrl3’s picture

Version: 5.x-2.3 » 6.x-2.9
Status: Closed (fixed) » Active

hi there -
i'm using your code and appreciate the post! but my users need to be able to perform edits & saves on form submissions and i realized that means the my 'auto number' was getting changed on each save (if other submissions have occurred b/c the count is bigger). so, i fixed that by defaulting my hidden field to 0 and only setting the auto-increment if the field is zero (i.e., on 'add', but not 'edit'). but - i really don't want the user to be able to change the number once it is assigned - after the initial 'add'. i don't see how to lock a hidden field. do you have a php suggestion for 'if field is not zero, do not change the number, always keep it what it is'? or better, how to lock a hidden field from change during an edit? thanks so much!!

quicksketch’s picture

Status: Active » Closed (fixed)

Support for custom code is no longer provided in the Webform issue queue. I simply couldn't keep up with the requests so now I'm only accepting feature requests, bug reports, or support requests dealing with usage of Webform without code.