Forum
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
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'?
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?
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: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?
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.