-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid overwrite only first field with last value #145
Avoid overwrite only first field with last value #145
Conversation
Hi @powdevel thanks for the PR! I appreciate the thorough description. |
Hi @colemanw, when all emails are a different type it works as expected, no patch needed for that. However when one or more emails are the same type it fails and overwrites the first email with the last email of the same type. |
Ok thanks. I'll go ahead and merge this and hopefully folks like @KarinG who use the dev version of this module will catch any issues before the next release. |
@davejenx - you're very familiar with this bit of webform_civicrm code - if you have time can you please have a look at this PR? |
@davejenx @KarinG @powdevel as a related issue #147 would like your feedback on this change: https://github.com/colemanw/webform_civicrm/pull/147/files#diff-59be2e079a691088e15ab3a80e0640a0R2513 Without that change it's only updating the actual phone number from submitted values (presumably the same for email). And it won't save custom data. With this change it will update all submitted values which I think is what we want? |
@mattwire Title on this PR maybe is not so precise as I'm investigating more on this bug.
I recently noticed that the code on Also noticed that, if there an email on the webform, the email user account of Drupal is being changed always on first iteration no matter the location set in the email field, no matter if it changes or not. It would produce in some cases to have a primary email for CiviHR and a different Drupal user account email. I'm trying to fix both errors and submit new PRs as soon as possible. |
@KarinG Looking at #121 I think the error is caused because of these lines on PD: currently I'm working with version 7-x.4.20 because that is the version that CiviHR uses. |
PD: The GIF that I posted above was done with the module patched with this patch, otherwise it will not save all values. |
I never thought someone would use multiple of type = home addresses (email etc). But what needs to remain fixed is that if in the webform -> CiviCRM tab a user configures an Address of type = home (note the GUI says -> that this will become is_primary) then it should become is_primary; before 121 billing address would become primary simply because it was the last address entered; Happy for you to rework this and make it better but we can’t regress on 121 and end up with the incorrect address designated as is_primary |
So your test needs to include a payment of some type -> common scenario: collect name + address (home) + hook up a contribution page to a payment processor and make a contribution via the webform (the billing address is pulled in from teh contribution page) |
You are welcome @KarinG. Thanks to you too. I understand about the tests to avoid regression for #121 What you are telling me is that currently Similar for emails, the first email will always be the new Drupal account email, no matter what. I think this should be written in the UI too, and preferably let the admin to choose to overwrite or not the Drupal account email with that first email. Now I have to rethink some things 😄 |
Not saying we don’t want to support multiple same location (like multiple home addresses) - it’s just something we’ve never seen/asked; if you can find a safe way to make that work without causing regression in the is_primary designation then for sure this is ok; |
@KarinG CiviCRM does not supports multiple addresses with the same location, so I think it doesn't have to be supported, however Beyond addresses... for phones, emails and probably some other fields, CiviCRM does support multiple fields with same location. What I'm going to do is to create the PRs to support those fields and probably other fields in the same situation. Until now the tests I had made saved all fields correctly. I even tested with multiple emails fields and multiple locations and everything is working fine. Like this: I going to test fields like phones, which can have additional types like "Landline" or 'Mobile". Tests to avoid regression on #121To avoid regression on #121 I tested with another webform with 2 address: one location work (primary) and the other one location personal. I remove all webform fieds from address 1, to not allow editing on first one but also do not change primary address. Like so: I also set this config in the contribution part: And the webform looks like this: Tests made with this webform saved data correctly too, primary keys for addresses where not swapped, wrongly overwritten, or anything else. PD: please tell me if the config for avoid regression on #121 is enough. Honestly I see #121 and I think that the modifications I'm doing right now will not make a regression, but will allow saving multiple fields correcly without primary keys confusion. PD2: the tests I am making include the patch in #146 to retrieve information correctly on webform load |
Excellent - and yes this works - I just pulled your edit into one of my test instances - and happy to also confirm is_primary continues to be handled properly. So this one is in - let's keep this merged. And then continue on from here. I've not tested anything other than this PR (thus far). Which one (between you and @mattwire is next)? |
@KarinG Cool! 👍 Tomorrow I will make a PR with the fix for "primary keys confusion" which works at least on my tests, allowing multiple fields to work in one form keeping primary keys correctly. |
I can look at this as is - Can you instead please look @mattwire ‘s PRs - they are related and I’d like your thoughts on it. |
@KarinG I think @mattwire is adding very important functionality which is different from this PR. I inspected the code and modifies different things from my PR. However as of now I had not make any tests on #147 as I don't know exactly the bug and how to reproduce it, I'm fairly new to CiviCRM. A summary: PD: I think that #145 #146 #147 #148 are compatible all together. |
Overview
Webforms with multiple emails values are not being saved correctly. The last submitted value is written to the first email field. Other emails are not being updated.
Before
Data before submission

Example configuration of the webform

Data when visiting the webform

Filling the webform with a second email

Visiting the webform again we can see that first email was overwritten with last email

From the Admin UI it confirms what the webform was showing: first email overwritten with last email.

After
Repeat steps 1 to 4 from "Before" for initial data, filling the webform and saving.
Data was stored correctly.

Technical Details
Attaching exported webform with node export:
webform-multiple-emails.txt
Site created for testing with civibuild using this command
civibuild create civi12 --type drupal-demo --civi-ver 4.7.27 --url http://civi12 --web-root /home/beto/buildkit/build/civi12
CiviCRM currently uses civicrm_webform 7.20, however this module was replaced with the last version found here https://github.com/colemanw/webform_civicrm
Comments
Base on the modifed code (shown below) this is probably not only applicable to emails but for fields which are not addresses.
