Public Methods - Richard1320/php-form-processor GitHub Wiki

There are various methods you can call from the form instance.

Render form

This method prints out the form HTML markup.

$form->render_form($action, $params);

The first parameter is action. This is the action attribute for the form telling it where to submit the data. If not given, it will submit it to the same page.

The second one holds various parameters.

Parameter Accepted Values Default Description
method post / get post Method to submit the form data
submit_name string submit Name attribute on the submit button
submit_value string Submit Value attribute on the submit button
action_html array empty Multi-dimensional array with "prefix", "buttons", "suffix" keys for extra HTML markup near the buttons. Useful for adding disclaimers or extra buttons.
classes array empty Array of classes to add to the form element.
enctype [media types] multipart/form-data if there is a file field, else application/x-www-form-urlencoded Enctype attribute of form.

Submit Form Data

This method submits the form data for validation. Data should be passed as an array that matches the fields array at initialization.

If data is not passed, it will attempt to get it from the $_POST, $_GET, and $_REQUEST superglobals, in that order. It is highly recommended that data is retrieved propertly and passed to this function. Letting it guess can lead to huge headaches when it doesn't work.

After validation, if there are any errors, both errors the the data will be saved in the $_SESSION superglobal. They can then be retrieved with the get_field_value method to set the default value next time.

$data = $_POST;
$form->submit_form_data($data);

Get Submitted Field Value

You can use this method to get the submitted value from the form. This function has to be run after the submit_form_data method. The key that gets passed is the field's array key during form initialization.

$key = 'title';
$value = $form->get_field_value($key);

Display Errors

You can use this method to get the submitted value from the form. This function has to be run after the submit_form_data method. Errors are saved in the session so it can still be printed after a redirect.

$form->print_errors();