In certain circumstances, which I haven't fully understood yet, you get this error when you're trying to save a webform that doesn't use a webform template:

Notice: Trying to get property of non-object i _webform_template_attach() (rad 141 av /mnt/persist/www/docroot/sites/all/modules/contrib/webform_template/webform_template.module).
PDOException: SQLSTATE[HY000]: General error: 1364 Field 'confirmation' doesn't have a default value: INSERT INTO {webform} (nid) VALUES (:db_insert_placeholder_0); Array ( [:db_insert_placeholder_0] => 63 ) i drupal_write_record() (rad 7036 av /mnt/persist/www/docroot/includes/common.inc).

I did some troubleshooting and saw that the problem is essentially that in webform_template_submit(), the variable $form_state['complete form']['webform_template']['source']['#value'] is sometimes set to "none" rather than 0 and that triggers the error.

Patch will be posted in a comment.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ordermind’s picture

Here's the patch!

rv0’s picture

Status: Active » Postponed (maintainer needs more info)

Cannot reproduce this
are you using any module that modifies form selects?

What version of drupal?

ordermind’s picture

Status: Postponed (maintainer needs more info) » Active

I'm using Drupal 7.17. There might be a module that modifies form selects, I'm not sure. The patch would be a good safety check in case there is one, right?

rv0’s picture

Status: Active » Postponed (maintainer needs more info)

I'm using Drupal 7.17. There might be a module that modifies form selects, I'm not sure. The patch would be a good safety check in case there is one, right?

Not at all!
I suspect that module that is modifying form selects is doing it wrong, and this issue should be taken to that module.
Please check your installed modules and report back here (or send me a list of all modules so I can investigate myself)

I have only tested up to 7.14,
I know 7.15 changed some things for option buttons, which may have also affected select lists.

I'm working on a new release for Webform Template, so I will test in 7.17 soon

Karthick_s’s picture

I dont use webform template but I use form builder for webform ui and I get this error on saving!

rv0’s picture

@Karthick_s
its not possible that you get this exact error when you are not even using webform_template.

Karthick_s’s picture

ya rv0 it may not be from this module but i got the following error

PDOException: SQLSTATE[HY000]: General error: 1364 Field 'confirmation' doesn't have a default value: INSERT INTO {webform} (nid) VALUES (:db_insert_placeholder_0); Array ( [:db_insert_placeholder_0] => 63 ) i drupal_write_record() (rad 7036 av /mnt/persist/www/docroot/includes/common.inc).

after doing some change in form_builder for webform module i solved it.

rv0’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

No reason to keep this open.

hansrossel’s picture

This also happens when you use display suite and have the webform template field hidden. Making the webform template field visible on the edit form solves the problem.

Jim Kirkpatrick’s picture

Version: 7.x-1.2 » 7.x-1.x-dev
Status: Closed (works as designed) » Active
FileSize
7.89 KB
963 bytes

This is still an issue for us...

The code mentioned in the OP and the patch in #1 works.... As mentioned there issue is in webform_template_submit(), where the check on $form_state['complete form']['webform_template']['source']['#value'] is set to "none" which passes the isset() check but doesn't mean there's actually a usable node ID to load in webform_template_node_insert($node).

A slightly cleaner version of #1 (and the original function) is to check that the result is a usable, numeric nid:

/**
 * Form submission handler for node forms.
 */
function webform_template_submit($form, &$form_state) {
  // Check and store the chosen nid of the template (if present).
  $template = $form_state['complete form']['webform_template']['source']['#value'];
  if (!empty($template) && is_numeric($template)) {
    // @todo SECURE THIS!!
    $_SESSION['webform_template'] = $template;
  }
}

I know not what circumstances/modules cause 'none' to be there in the source #value rather than nothing, but it broke our site and has been hit by several people now. Our custom code does not do anything like this... Also attached is webform_templte-enabled-modules.txt which is the output of drush [sitename] pm-list --status=enabled --type=module --no-core in case any module/version listed could be the cause.

Patch of the above code is attached for consideration, which regardless of the cause makes the function a little more resilient and cleaner than before.

rv0’s picture

at first sight, code in above patch will fail when $form_state['complete form']['webform_template']['source']['#value'] is empty

I'd really love to be able to reproduce this issue. I see your site uses options_element module, perhaps we need to check that.

Jim Kirkpatrick’s picture

@rv0 -- yes you're right, was very rushed when doing this and missed the obvious... Having a check for !empty() before the assignment of the variable is absolutely needed.

And I found the cause of this on our site: another developer wrote some deeply retarded jQuery that was removing the items out of the template select dropdown. Badness...

So our need for the patch is gone, though a similar 'belt and braces' is_numeric() check for sanity might reduce issues caused in other circumstances (e.g. by that field being hidden by DS per #9). Thanks.

Jim Kirkpatrick’s picture

Title: DB error on webform form_submit » DB error on webform form_submit when Webform Template choice field hidden.
FileSize
971 bytes

A non-broken version of my patch in #10, plus tweak for doc comments and dealing with @todo SECURE THIS!!:

/**
 * Form submission handler for node forms.
 *
 * Stores the chosen nid of the webform template, if selected.
 */
function webform_template_submit($form, &$form_state) {
  if (isset(form_state['complete form']['webform_template']['source']['#value'])) {
    $template = check_plain($form_state['complete form']['webform_template']['source']['#value']);
    if (is_numeric($template)) {
      $_SESSION['webform_template'] = $template;
    }
  }
}

Patch attached.

Jim Kirkpatrick’s picture

Status: Active » Needs review
jgtrescazes’s picture

Status: Needs review » Reviewed & tested by the community

Hi,
I had same error message when web form template form element was hidden and error disappear when showing it again.
I confirm the above patch #13 solve the issue.

jgtrescazes’s picture

Status: Reviewed & tested by the community » Needs work

Hi again,

In fact it doesn't totaly solve the problem as sometime $template is equal to 0.
And in this case it gives the same error.

Bellow code works for me but it may be cleaner to fix it at form level and ensure to always get the same value.

<?php
/**
* Form submission handler for node forms.
*
* Stores the chosen nid of the webform template, if selected.
*/
function webform_template_submit($form, &$form_state) {
  if (isset(form_state['complete form']['webform_template']['source']['#value'])) {
    $template = check_plain($form_state['complete form']['webform_template']['source']['#value']);
    if (!empty($template) && is_numeric($template)) {
      $_SESSION['webform_template'] = $template;
    }
  }
}
?>
rv0’s picture

Issue summary: View changes
Status: Needs work » Closed (works as designed)

Closing old issues.. Please re-open if it is still relevant today