PHP Fatal error: Call to a member function totalAmount() on a non-object in /var/aegir/platforms/myplatform/sites/example.com/modules/contrib/payment/paymentreference/paymentreference.module on line 569

Page 1: some fields
page 2: payment reference

Go to page 2
Go 'Back' a page
Go the page 2 again... white screen of death

Comments

xano’s picture

Title: Fatal error after going back and forth between pages » Component value is corrupted in multistep forms
Project: Payment for Webform » Webform
Version: 7.x-1.x-dev » 7.x-3.x-dev

I have been digging through the code for a while, and it looks like Webform incorrectly sets the component value, but indeed only for multistep forms.

What happens is that Webform uses the value of the button that is part of the component as the component value.

quicksketch’s picture

Title: Component value is corrupted in multistep forms » Component value is corrupted in multistep forms (w/ Payment for Webform)
Category: bug » support
Status: Active » Postponed (maintainer needs more info)

I don't plan on fixing this issue considering it seems specific to Payment for Webform. If there is a particular patch or suggestion that can be made to avoid this problem in Webform, I'm happy to take a look, but I probably won't go digging into this particular conflict without more information.

helmo’s picture

A related error:
Notice: Undefined offset: 0 in _webform_display_payment_webform() (regel 94 van /var/aegir/platforms/myplatform/sites/example.com/modules/contrib/payment_webform/payment_webform.webform.inc).

@quicksketch: is it normal that the _webform_display_payment_webform() hook is called when the component is on another page?

I'm attaching two patch files to test for this condition and at least avoid a WSOD.

helmo’s picture

Status: Postponed (maintainer needs more info) » Needs review
quicksketch’s picture

@quicksketch: is it normal that the _webform_display_payment_webform() hook is called when the component is on another page?

The "display" hooks are only called when a component is having its value (rather than the form element) displayed. This happens when e-mails are sent, when viewing a submission, or when rendering a token for a previous field's value. Normally, none of these things happen until the final form is submitted. If it's happening between pages, there may be some kind of processing that is happening that Webform is not anticipating.

helmo’s picture

Project: Webform » Payment for Webform
Version: 7.x-3.x-dev » 7.x-1.x-dev
Category: support » bug

Moving this back to the Payment for webform queue, to get some review on the patches from #3

Status: Needs review » Needs work

The last submitted patch, 1994392-paymentreference-test_pid.patch, failed testing.

helmo’s picture

Status: Needs work » Needs review

Thanks bot... two patches for two modules...

helmo’s picture

@Xano: Any thoughts on this?

xano’s picture

Status: Needs review » Needs work
+++ b/payment_webform.webform.inc
@@ -81,7 +81,12 @@ function _webform_submit_payment_webform($component, $value) {
-  $pid = $value[0];
+  if (isset($value[0]) &&  !empty($value[0])) {
+    $pid = $value[0];
+  } else {
+      return;
+  }
+
   $label = t('Payment !pid', array(
     '!pid' => $pid
   ));

Just empty() should work too, and can you make sure this complies with the coding standards?

Also, can you explain the rationale behind this patch?

helmo’s picture

Just empty() would probably be enough.

Have you also looked at the second patch from #3 (for the payment_reference module)?
Maybe that the comment line from there could also be used in the first patch.

xano’s picture

The comment is short, cryptic and refers back to this issue, so it needs some more love. What is a "bogus string value", why can it happen, and why is this the right solution?

xano’s picture

+++ b/paymentreference/paymentreference.module
@@ -526,6 +526,12 @@ function paymentreference_field_access($op, $field, $entity_type, $entity, $acco
+
+  // Protect against a bogus string value: https://drupal.org/node/1994392
+  if (!is_numeric($pid)) {
+    $pid = 0;
+  }

We shouldn't do this. The form element documentation clearly states that the default value needs to be an integer. If there is a chance that a module sets something else, that module will have to add this check itself.

helmo’s picture

Could you link the 'form element documentation' documentation your referring to?
Of do you mean the #default_value in:

function paymentreference_element_info() {
  $elements['paymentreference'] = array(
    '#input' => TRUE,
    '#process' => array('paymentreference_form_process_paymentreference'),
    // The PID of a payment as the default value.
    '#default_value' => 0,

xano’s picture

yes. That documentation says the default value which needs to be a Payment PID, which in the class Payment is documented as an integer.

dgtlmoon’s picture

Also able to reproduce this if you delete a payment and then return to the original webform, WSOD & same error

xano’s picture

Issue summary: View changes

Bump. Does this problem still occur?

helmo’s picture

Yes, I recently tried it without my patch https://www.drupal.org/files/1994392-paymentreference-test_pid.patch and quickly re-applied :(

xano’s picture

Good to know! We can't commit that, however, as this is a Webform issue. We'll either have to fix Webform or add a workaround to Payment for Webform.

xano’s picture

What about this patch from #3. Does that work?

helmo’s picture

No, unfortunately the payment_webform patch does not help :(
I need the payment_reference patch to keep it working.

xano’s picture

Could someone answer this question from #12?

What is a "bogus string value", why can it happen, and why is this the right solution?