Skip to content
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-21523 add form rule for repetition fields in scheduled reminder form #11377

Merged
merged 1 commit into from
Apr 9, 2018

Conversation

lcdservices
Copy link
Contributor

@lcdservices lcdservices commented Dec 5, 2017

Overview

Add form rule to schedule reminder form to require both frequency interval fields if repetition is enabled.

Before

Frequency interval fields were not required. If the value was left blank it caused an SQL error when the scheduled reminder job was triggered.

After

User must enter a value for both fields. No SQL error generated.

Technical Details

The rule is slightly different for the two fields. For repetition_frequency_interval we require a non-null/non-zero value as the frequency of the repetition must be a meaningful value. For end_frequency_interval (until...) we allow a zero value, as that is a valid use case.


@@ -350,6 +350,13 @@ public static function formRule($fields, $files, $self) {
$errors[$recipientKind[$fields['recipient']]['target_id']] = ts('If "Also include" or "Limit to" are selected, you must specify at least one %1', array(1 => $recipientKind[$fields['recipient']]['name']));
}

//CRM-21523
if (!empty($fields['is_repeat']) &&
(empty($fields['repetition_frequency_interval']) || ($fields['end_frequency_interval'] == NULL))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lcdservices because you used == instead of === I don't think those two conditions are actually different.
Php thinks that 0 == NULL but not 0 === NULL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it seems like we should use the strict operator, but it doesn't work when you do. I believe that's because the values we receive are cast as strings, not integers. If we use the strict operator an empty value for the end_frequency_interval field does not trigger the validation.

@eileenmcnaughton
Copy link
Contributor

@colemanw this appears like a minor change but stalled in discussion on your review? (It's form validation so a fairly safe area of code)

@colemanw
Copy link
Member

colemanw commented Apr 6, 2018

I'm still slightly confused by the operators but I've tested out the patch and it works as described.
I've just amended the commit to include red asterisk required markers for visual consistency.

screenshot from 2018-04-06 11 47 58

@colemanw colemanw merged commit 0699492 into civicrm:master Apr 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants