[Drupal] How to update / modify the data submitted via Drupal webform when submitting the form?
Webform is a Drupal module that can help webmasters create submission forms like survey forms, contest forms, contact us form etc without any custom programming. Usually webform submissions will result in the data being inserted as a new row into table 'webform_submitted_data'. But our client requirement was to update an existing submitted data from the table 'webform_submitted_data'. If you want to know how to update an existing webform submission then continue reading
webform.submissions.inc (webform/includes/webform.submissions.inc) file has functions related to submitting new data, editing, or viewing data. Check out this file to see how webform handles these functionalities on a Drupal site.
For updating the webform data you will have to pass the value of submission id from webform (sid).
- Set one field as primary key like emailid from the webform
- Alter the webform by using form alter hook
- Passing the value of submission id from webform (sid) to the variable " $form['details']['sid']['#value'] " .(Please see the example.)
eg:
<?php
function modulename_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'webform_client_form_id') {
$query = db_query("SELECT sid FROM webform_submitted_data where cid = 59 and data = 'data1'");
$result = db_fetch_array($query);
$form['details']['sid']['#value']= $result['sid'];
}
}
?>