Buy Now
Sign in

PHP validation with message array

healyhatman , June 26 2017
Answered
Featured
healyhatman
This has probably already been gone through but I just figured it out so....​
​​
​If you want to validate a bunch of things in PHP (serverside) and have it display helpful messages.​
​​
​1. Add a PHP action under setup. For example: ​
​​
Name: customValidation​
​​
​​
$valMessage = [ ];​
​if(empty($this->data("aTextField", "")))​
​{​
​ $valMessage[ ] = "The text field should not be empty";​
​}​
​​
​if($this->data("aNumberField", "") != 12)​
​{ ​
​ $valMessage[ ] = "Number field should be 12";​
​}​
​(etc etc etc etc)​
​​
​return $valMessage;

​​
​​

​​
​Each message just do $valMessage[ ] = (the message) to add it onto the message list​
​​
​2. Put in an event switcher​
Data provider: {var.empty:customValidation}​
Events: true, false​
​click update events list​
​​
​3. Drag a message and an event loader into the "false" bit​
content: {var:customValidation}​
​​
​​
​Now, if there are any error messages they all get displayed correctly as a list with bulletpoints and everything. The event loader reloads the page and stops the crappy data being submitted any further. Makes sure you put it UNDER the message, or the message won't be displayed.
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman