Hi
Not sure if I'm missing something obvious here, but I've got a form with some conditional questions which I need to process using the submission data.
I need to react when some of a multiple selection questions checkboxes are not selected but not if the question has not been asked.
At present I can't tell the difference if the question has not been asked (conditional) or non of the checkboxes have been selected. In both cases the submission array gives an empty array for the component ID.
Is there a way to determine from the submission data, or any other information, the difference?

Comments

quicksketch’s picture

Unfortunately, I can't think of a way to calculate this easily. Checkboxes in particular are notorious for presenting this kind of problem, since if they're not checked, simply nothing gets submitted to the POST array (as if they didn't exist at all). The only suggestion I can think of is if you duplicate the data checking on the server-side for the original question to determine if the checkboxes were shown in the first place. If this is a single-page form, you could also probably directly check the $form['submitted']['your_checkboxes']['#access'] property to see if the checkboxes were shown in the first place. Multiple page forms get tricker because different pages populate the $form array at different times.

donaldp’s picture

Thanks for the feedback.

I need this to work using just the node id and the submission id, and I've now managed to get around the problem in a not particularly clean way.
I've got a content type which is linked to the appropriate webform component question using it's cid. I've now added to this content type a reference to the webform component question and answer that caused the question to appear. I can then look up the conditional question and it's response in the submission data to determine if the question was visible and therefore asked. This linking in my content type is only needed when it is required to respond to a conditional question not being answered.

This is not particularly clean as it's partially duplicating the conditional linking between the webform components that is built into webform and it is specific to my problem but I had to get this working very quickly.

I would have much preferred to have used the existing conditions. Is there a relatively easy way to get access to the conditions? For example, given a webform node id and component id, returning the component id(s) and conditions that determines its visibility.

quicksketch’s picture

I need this to work using just the node id and the submission id, and I've now managed to get around the problem in a not particularly clean way.

If that's the case, maybe you should just build the submission renderable and check if the field you want to check is visible:

    $renderable = webform_submission_render($node, $submission);
    if ($renderable['fieldset']['field_to_check']) {
      // Field exists according to conditional rules.
    }
quicksketch’s picture

Issue summary: View changes
Status: Active » Closed (fixed)

Closing after lack of activity.