Forum

Thread tagged as: Problem, Forms

Form submit required validation not working

Hi guys

This is on 2.4.5:

<perch:input type="select" label="Annual Service Due" id="service_due" required="true" options="Select|,January,February,March,April,May,June,July,August,September,October,November,December" class="required" />

How can we validate a select field in this way? The option Select has an empty but the server-side validation doesn't pick that up.

Thanks

Russell Back

Russell Back 2 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

If you don't give an option a value, then I believe the browser uses the label as the value.

Drew McLellan said:

If you don't give an option a value, then I believe the browser uses the label as the value.

Is there any way in Perch to validate against a string? i.e. value != '' AND value != 'Select'?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Not built in - you'd need to write a validation helper. How's your PHP?

Pretty good - is there any documentation available on this or do I need to dig into the code?

Drew McLellan

Drew McLellan 2638 points
Perch Support

I need to add it to the docs, but it's pretty simple. On your input, set the helper attribute with a static class method:

helper="PerchMembers_Members::check_email"

This will call the method with the value entered into the field. Return true or false, and that's it.

Drew McLellan said:

I need to add it to the docs, but it's pretty simple. On your input, set the helper attribute with a static class method:

helper="PerchMembers_Members::check_email"

This will call the method with the value entered into the field. Return true or false, and that's it.

Thanks, Drew. Bearing in mind we're talking about creating a new helper method, where should we be creating the class that contains that new method?

Drew McLellan

Drew McLellan 2638 points
Perch Support

It can go anywhere as long as it's in scope. Simplest way would be to put it in a file and include it within config/apps.php .

My PHP knowledge is not that extensive.
Any ideas, where I can find instructions on how to pull this off?
I need to verify, that a text field is filled with a specific sting. That string should not be visible in the DOM.