Form processing made easy with PHP
User defined callback functions for form elements
No need for complicated if/else structures
Supports optional inputs and array data
Automatic filling for value attributes, selected attributes etc.
Asynchronous value checks & form submit (configurable)
Please see demo.php for complete usage instructions
A form processed with SnappyForm can be tested here: https://www.pickmybra.in/snappy/demo.php
A list of methods:
- Required only if multiple forms are to be processed.
- Calling this before deploying settings or printing form values limits the effects on that particular form only.
- takes a string or an associative array as parameter, sets general or element specific error messages
- $msg = "This error message will be shown for all inputs";
- $msg["element_name"] = "element specific error message";
- sets input filtering rules for different inputs
- associative array formats:
- $rules["element_name_1"] = array("filter_function_1");
- $rules["element_name_2"] = array("filter_function_2" => array("param1", "param2"));
- enable / disable asynchronous form submissions
- enable / disable asynchronous individual input value checks
- enabled / disable form reset after successful asynchronous submit
- if set, replaces form submit button's value with the given $value after it has been clicked
- also disables the button until a response is received from the server
- works even if set_async_submit() is set to false
- calls $function_name after successful form submission.
- If $instance is provided, method named $function_name will be called from the provided instance
- required for asynchronous form submits!
- this function must return true or false
- a loading message can be shown during the asynchronous input value checks
- will be shown in the error message container, unless an input specific loader position is defined with the loader() method
- default values can be set for the form inputs with this method
- associative array format: $values["element_name"] = "element default value";
- this method can be called multiple times, but defining the same element_name again will overwrite previous settings for that given element
- processes form data, is triggered by form element named $element_name
- also accepts multiple element names in array format, if multiple forms are processed with the same SnappyForm instance
- $form_method can be null/empty, "post" or "get"
- returns NULL if no form submission was detected,
- false if input values failed to pass the defined rules
- true if input values passed the rule check
- resets all form values to defaults (for example, after successful submission)
- returns a success message after successful form submission (=rule check passed)
- if callback function is defined, (bool)true output value is expected for success message to be shown
- returns an error, if callback function is defined and it returns a non true value
- returns an input value error set with set_error_messages(), if errornous value was provided and error message is defined
- places the loading message, which will be shown during asynchronous input value checks (if set)
- if loading message is defined and loader() is not called, the loading message will be shown in the element specific error message container instead
- returns submitted value for the given input/element
- if second parameter is defined and it matches the submitted value, third parameter is returned. returns empty string if values do not match.
- prints javascript handler ( < script> ... < /script> ) for asynchronous value checks and form submission
- takes $target_file as an optional parameter - required only if the form is printed and processed in different files
- call this function only after the form has been printed, not before it!