A client site has 2 forms which use additional processing to route forms to appropriate recipients based on the value selected in a Select element. The additional processing code is fundamentally similar (switch case statements changing the value of a hidden field, which is then used as the recipient address for the message), and in both forms behaves as expected when the user sending the form is logged-in to the website.

However, processing fails on one of the two forms iff the form is being submitted by an anon user. (I know this by looking at the value of the hidden field: When users are logged in, the value is changed; when not logged-in, the value doesn't get changed.)

I'm struggling to find differences between these two forms, and can't see any. The additional PHP code is fundamentally similar, as I've said -- I'll paste samples in first comment, but I don't think that's it.

Anyone have an idea where I should be looking to figure out what the source of the problem is?

What I've looked at so far:

* Examined the settings and content for each webform side by side to eliminate as many differences as possible.
* Compared additional processing PHP code line by line.
* Upgraded to most recent DEV build of webform_php.

Comments

escoles’s picture

This php (anonymized) is processed for both logged-in and anon users:

<?php
// 'ASK THE EXPERTS'
/* 
 * Detect value of 'My question relates to', and 
 * set recipient as appropriate. 
 **/
switch ($form_values['submitted_tree']['category']) {
  case "nitinol-alloys-and-melting":
  case "nitinol-mill-products":
    $category_recipient = "user-y@example.com, user-z@example.com";
    break;
  case "nitinol-tube-wire-sheet-strip":
  case "nitinol-tube":
  case "nitinol-wire":
  case "nitinol-strip":
    $category_recipient = "user-a@example.com, user-b@example.com";
    break;
  case "nitinol-sheet":
    $category_recipient = "user-c@example.com";
    break;
  case "component-prototyping":
  case "fab-and-finishing":
  case "testing-analysis-quality":
    $category_recipient = "user-a@example.com, user-b@example.com";
    break;
  // "Other" has no reliable test value -- must use failover
  default:
    $category_recipient = "user-x@example.com";
	break;
}
$form_values['submitted'][8] = $category_recipient;

This php is processed only for logged-in users:

<?php
// 'REQUEST A QUOTE'
/* 
 * Detect value of 'Interest', and 
 * set recipient as appropriate. 
 **/
switch ($form_values['submitted_tree']['interest']) {
  case "nitinol-alloys":
  case "nitinol-mill-products":
    $interest_recipient = "user-a@example.com, user-b@example.com";
    break;
  case "nitinol-tube":
  case "nitinol-wire":
  case "nitinol-sheet":
  case "nitinol-strip":
  case "nitinol-components-assemblies-prototyping":
  case "nitinol-components-assemblies-production":
    $interest_recipient = "user-e@example.com, user-x@example.com";
    break;
  case "samples":
    $interest_recipient = "user-d@example.com, user-x@example.com";
    break;
  // "Other" has no reliable test value -- must use failover
  default:
    $interest_recipient = "user-x@example.com";
	break;
}
$form_values['submitted'][20] = $interest_recipient;

When the form is submitted by a logged-in user, $form_values['submitted'][20] gets set to a value based on the value of $form_values['submitted_tree']['interest']. When the form is submitted by an anon user, it doesn't.

Note: The presence of opening-tags only is accurate -- my understanding is that's the best practice for including PHP in these fields -- if I'm mistaken about that, please correct me.

escoles’s picture

Title: Additional Processing fails if for anon users » Additional Processing fails for anon users

Additional things I've tried:

* Working code ended with a newline; I added a newline to the failing code, and it still failed for anon users.
* Added closing PHP tag (?>) for the failing code -- still fails.

Also fixing typo in my title ;-).

MORE:

* Corrected missing user 0, which I became aware of through Drush failures. Still fails.

escoles’s picture

I further verified that I can clone the form, and the additional processing will work in the clone. So that means it's something about this webform, very very specifically. Off to check the UID of the creator....

EDIT: There is almost no discernable difference between the original and the clone. The few differences are things like the VID, title, URL path.

So a fallback position can be to enable the clone and use it to replace the original. Which is a highly unsatisfactory solution, since it means I have no assurance the thing won't fail again.