We have a form where the date of birth is optional. In 7.x-1.3, when a date is not entered, the salesforce_webforms date filters return '0000-00-00', and what's saved in the Salesforce contact for birth date is today's date. In 7.x-dev with #2797113: Date of birth conversion goes wrong, not entering a date results in Salesforce refusing to save the record because salesforce_webforms_date[time]_filter() returns gibberish when given an empty string.

Proposed resolution

In salesforce_webforms_date[time]_filter() check if the string was successfully parsed into a date and return NULL if it was not. Salesforce seems to be satisfied with NULL in my tests.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ChaseOnTheWeb created an issue. See original summary.

ChaseOnTheWeb’s picture

Status: Active » Needs review
FileSize
1.16 KB

Patch attached

dbcollies’s picture

Thanks for the patch. I've got a lot on my plate right now, but I'll review this as soon as I can.

dbcollies’s picture

Assigned: Unassigned » dbcollies
Status: Needs review » Needs work

The basics of this patch look good, but I think I want to expand on it a bit. Rather than silently converting any bad string into a NULL, I think it would be better to do the following:

  • If the string is empty/white space, then do as you are doing in your patch
  • If not blank, then treat it as an error condition.

Of course the current API doesn't allow filters to raise error conditions, so that may need to be visited. I'll look into it some more.

dbcollies’s picture

Assigned: dbcollies » Unassigned
Status: Needs work » Needs review
FileSize
6.73 KB

I've put together a new patch which hopefully addresses your concerns, as well as the changes I talked about above.

Please give it a try and let me know if you uncover any issues.

dbcollies’s picture

I've reworked my patch slightly. I moved where the processing of suppressing the save and generating messages to AFTER the submission hooks have been called, in case a hook handler also wants to make use of this new facility.

chill5-0’s picture

I'm not sure if this is related - I have a date field in which the "day" dropdown is hidden (webform option). Webform says the default value that's saved is "1", but when I try submitting the webform, I receive an error "Error creating Salesforce object: [name of my field]: invalid date: Sun Nov 30 00:00:00 GMT 2". Also, the date I am submitting is Jan 2018, but the error msg is for Sun Nov 30. I have 7.x-1.x-dev installed and tried applying patch #6, but I think it's already applied in this version of the module. Not sure if this adds any insight, but thank you for creating this module - it has been very helpful in pushing data to our SF instance.