-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
CRM-18427: Submitted custom data values not reloaded on form when validation fails #8269
Conversation
monishdeb
commented
Apr 29, 2016
•
edited by civicrm-builder
Loading
edited by civicrm-builder
- CRM-18427: Submitted custom data values not reloaded on form when validation fails
Jenkin, test this please |
@colemanw @eileenmcnaughton as per https://issues.civicrm.org/jira/browse/CRM-16676?focusedCommentId=86474&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-86474 reason behind this bug, this is the only fix I got, as now via 'civicrm/custom?type=&' loads CRM_Custom_Form_CustomDataByType snippet which only got info what we provide via url's parameters. This fix contain -
|
jenkins, retest this please |
Test build failure is not related |
@@ -1377,7 +1377,13 @@ public static function setDefaults(&$groupTree, &$defaults, $viewMode = FALSE, $ | |||
} | |||
} | |||
else { | |||
$checkedValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($value, 1, -1)); | |||
if (is_array($value) && count($value)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tested this patch by adding a new contribution & filling it in with contribution details & custom field details but no amount. I save the custom data disappears. However, with this patch it does not.
I'm just going through the patch to see if it makes sense / seems risk free.
This line seems risk free as an array would not have previously been handled & the non array path is unchanged
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested radio, checkbox, autocomplete, date, multiselect, select, adv multiselect..
I think this is OK - it works & as far as I can see by getting the values only for specific fields (custom_xx) it's safe & being in the Custom class it should be fairly hard for someone to foolishly extend it to put credit card fields into the url. Having said that, odd interaction with the $_POST array makes me inherently a little nervous so I'd really like @colemanw or @totten or @xurizaemon to quickly eyeball this & confirm they don't see any hole that I'm missing |
Jenkin test this please |
I'm not comfortable with this ... can't articulate very well right now, but -
So using $_GET feels like an incomplete/not correct fix to me. |
@xurizaemon I have a plan to fix that. How about we capture the same logic to add/delete attachments in activity, for custom file field too ? So now when user uploads a file then on submit, it actually made an entry in civicrm_file and other necessary table, so when the page reloads on validation error, it fetch the saved file entry (show as a link against the custom file field) BUT now you have a trash icon against the file link so you can delete and upload a new file. #2 and #3 I agree thats it not right to pass such personal data and its weird to pass large input data via $_GET. So I was thinking what if we use cache to store/fetch this submitted values and later used to set default custom values on form reload!! @eileenmcnaughton @colemanw is it ok ? |
@monishdeb do you understand why these form fields need to be treated "specially"? I don't yet get the underlying cause of the need for this workaround. (Sorry, I know I'm chiming in late here.) |
@colemanw I feel like you need to look at this as you fixed something similar on the payment form |
@monishdeb I agree that the cache option is a good one. Using $_POST instead of $_GET also seems like an acceptable solution. |
@colemanw @eileenmcnaughton I have updated the PR and this is my change ac8833f as now we are storing the custom data in cache rather the passing it to url. As you can see I used to
However $_FILE uploads doesn't work not only for custom file field but also for other entity files e.g. activity attachments. So it should be raised as a separate issue. |
} | ||
// Generate cache key against which submitted custom value will be stored | ||
$cacheKey = implode('_', | ||
array(__CLASS__, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__CLASS__
will always be the same e.g. for forms open in multiple tabs. Do we have access to qfKey here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya I tried with qfKey earlier but getting some trouble with it as formatGroupTree() function is being called by multiple form as in here 'CRM_Custom_Form_CustomDataByType' form which is called via loadPage and entity form. So qfkey keeps changing for this two form instance. I tried to use get_class($form) != 'CRM_Custom_Form_CustomDataByType'
as another flag to set/get qfkey but it throws invalid session handling error on page reload. Still lemme check if we can make use of qfkey.
Done, updated the PR with f22fdc2 . Used qfKey only to be use a cache key. |
@@ -1892,7 +1894,9 @@ public static function formatGroupTree(&$groupTree, $groupCount = 1, &$form = NU | |||
|
|||
if ($form) { | |||
if (count($formValues)) { | |||
$form->assign('submittedValues', json_encode($formValues)); | |||
$qf = $form->get('qfKey'); | |||
$form->assign('qf', $qf); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'qfKey' seems like a better name for this smarty variable.
Thanks for all the work on this, y'all . I can test whenever the patch is ready, so just let me know.
I'd say there's a low expectation that this needs to work. A fair number of web applications I use don't save the upload file value when you fail validation. |
@josephlacey feel free to test now; my last suggestion was a NFC. |
@colemanw done (but can't rename the url param to qfKey as it overrides the qfkey of corresponding |
PR is ready for test :) |
Tested the PR with different input custom fields, changes works fine for all of them. |
@josephlacey I am merging this PR as Jitendra had already tested for all kind of custom fields except file. Feel free to reopen the ticket if ya find any other bug. |