I have following business scenario:
1. User fills out the form (webform module)
2. User clicks on button "Submit"
3. The PDF file is generated, (user can download it), and then user is redirected to page where he can see "thank you note" and info what to do with downloaded PDF.
I would like to call PDF generation method when the form is submitted, so that user that fills out the form can get the PDF (and not only admin).
I tried to look at the code, but since my PHP experience is very limited I would need some help from you.
I have found two functions in webform2pdf, which, I believe, are responsible for generating PDF:
- webform2pdf_download_pdf_form(&$form_state, $node)
- webform2pdf_download_pdf_form_submit($form, &$form_state)
As far as I understand I should call one of them when user clicks SUBMIT button on the form. I would go with the first one, as second one is probably for generating PDF from multiple records.
Having this I identified function in webform module, in webform.module file, called:
- webform_client_form_submit($form, &$form_state)
which, I belive, is called after user clicks SUBMIT button. It looks like this (just last two statements):
if (isset($form_state['values']['submission'])) {
drupal_set_message(t('Submission updated.'));
$redirect = NULL;
}
elseif (valid_url(trim($node->webform['confirmation']), TRUE)) {
$redirect = trim($node->webform['confirmation']);
}
// Check if the form should redirect to an internal URL, strip tags off
// first in case a WYSIWYG editor messed it up.
elseif (preg_match('/^internal:/', trim(strip_tags($node->webform['confirmation'])))) {
$path = preg_replace('/^internal:/', '', trim(strip_tags($node->webform['confirmation'])));
$redirect = array(trim($path), 'sid='. $sid);
}
elseif (preg_match('/^message:/', $node->webform['confirmation'])) {
$message = preg_replace('/^message:/', '', $node->webform['confirmation']);
drupal_set_message($message);
$redirect = NULL;
}
else {
$redirect = array('node/'. $node->nid .'/done', 'sid='. $sid);
}
$form_state['redirect'] = $redirect;
Hence I should add the webford2pdf function invocation somewhere at the end of webform_client_form_submit function, probably just before $form_state['redirect'] = $redirect; . (Please correct me if I'm wrong...)
The question is, assuming my thinking until now is correct, what parameters should be passed to webform2pdf_download_pdf_form function in order to generate PDF?
Hope some could help me in this. Please let me know if I can provide any more information.
Thanks!
Damian
Comments
Comment #1
shafter commentedYou should probably write a new module, and implement hook_form_alter for the specific webform submission.
Use
$form_state['values']['details']['sid']to get the id of the submission, and usewebform2pdf_submission_download_pdffunction of this module to download PDF.For more information about the output, check out http://www.tecnick.com/pagefiles/tcpdf/doc/com-tecnick-tcpdf/TCPDF.html#....
You can also make a patch if you have successfully done, what you wanted to.
Comment #2
max falduto commentedHi Dewu,
I am interested too building a form generate pdf on the fly!
Any news about your work?
I was looking for to a module let user generate a print file (pdf) when form is submitted.
Nothing results in my search, I'll became mad !
Thank You everybody for help!
Max
PS: I ll pay anyone help me.
Comment #3
mr.york commentedComment #4
jaroslaw.kaminski commentedI think this will help http://drupal.org/node/1264650
Comment #5
mboory commentedI know it has been sometime since this has been posted, but I am trying to do the same thing. Is there a way with the current Webform2PDF to achieve this in the admin, or will I need to edit the module? If I have to have to edit the module is what do I have to do?
Thanks