Super simple notice coming from _webform_submit_date, and super simple to fix with some issets.

Issue fork webform-2666088

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Steven Jones created an issue. See original summary.

steven jones’s picture

Status: Active » Needs review
StatusFileSize
new562 bytes
nicrodgers’s picture

Good catch. Might be better to use !empty rather than isset though?

danchadwick’s picture

Status: Needs review » Postponed (maintainer needs more info)

Instructions to reproduce? I saw the same code in another path, but I don't see how these array elements can be missing. Empty strings, yes. Missing? Don't know how.

liam morland’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

If you are still seeing this in the latest development version of Webform, please re-open and provide instructions to reproduce the issue.

kodiak324’s picture

One of our sites has an extremely complex webform with a lot of conditions and we are seeing this error. When a date field is hidden on a form because of a condition, a null gets passed to _webform_submit_date() and results in this notice being thrown. This also occurs with time fields in _webform_submit_date() and webform_time_convert().

kodiak324’s picture

Status: Closed (cannot reproduce) » Active
liam morland’s picture

Can you create steps to reproduce? Does the patch work? If so, please make an issue fork with it.

kodiak324’s picture

When a webform is submitted that has a date field hidden by a conditional, the following notice is thrown:
Notice: Trying to access array offset on value of type null in _webform_submit_date() (line 480 of /var/www/html/sites/all/modules/webform/components/date.inc).

Similarly, when a webform is submitted that has a time field hidden by a conditional, the following two notices are thrown:

Notice: Trying to access array offset on value of type null in webform_time_convert() (line 507 of /var/www/html/sites/all/modules/webform/components/time.inc).

Notice: Trying to access array offset on value of type null in _webform_submit_time() (line 364 of /var/www/html/sites/all/modules/webform/components/time.inc).

The referenced functions appear to receive the value ‘null’ for each field that is hidden by a conditional. Attempting to access array elements from a null value is not possible, so the notices are thrown.

Steps to reproduce:

  1. Install the webform module and required dependencies
  2. Create a new webform
  3. Add a “Select options field” with the label “What do you want to do?” and the following two options:
    date|Enter a Date
    time|Enter a Time
  4. Add a “Date” field with the label “Date” and default settings
  5. Add a “Time” field with the label “Time” and default settings
  6. On the conditionals tab, add two rules:
    1. If “What do you want to do?” is “Enter a Date” then “Date” is “shown.”
    2. If “What do you want to do?” is “Enter a Time” then “Time” is “shown.”
  7. Go to the form and select “Enter a Time” from the “What do you want to do?” options. The “Time” field should show. Submit the form with or without entering a time. You should see the notice about _webform_submit_date() on the confirmation page.
  8. Go back to the form and select “Enter a Date” from the “What do you want to do?” field. The “Date” field should show. Submit the form with or without entering a date. You should see the notices about webform_time_convert() and _webform_submit_time() on the confirmation page.

This patch mitigates the warnings by using empty() to check for values instead of checking for empty strings in expected array elements. empty() suppresses the notices when the variable being checked is not actually an array, when the expected key is not set within the array, or when the array member contains an empty string or otherwise falsey value.

Tested with Drupal 7.81 and Webform 7.x-4.24 via the official Drupal Docker image.

jweowu’s picture

StatusFileSize
new1.61 KB

This is the diff file for kodiak324's merge request !33 in comment #9. Please attribute it correctly if this is committed.

Attribution: kodiak324 at Rochester Institute of Technology

liam morland’s picture

Status: Active » Needs review
vladimiraus’s picture

Status: Needs review » Reviewed & tested by the community

liam morland’s picture

Title: Pesky notice in _webform_submit_date » Handle undefined date/time components
liam morland’s picture

Merge request as a patch.

liam morland’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.