Home  ›  AJAX Form Pro: + Admin Panel & Database  ›  How to Add a Custom Validation to a Field

How to Add a Custom Validation to a Field

This feature allows you to validate an input by using a custom PHP script. For example, the visitor must fill an e-mail address that is already in a database of yours. OR, he has to enter a product license key that should match one that is in your records.

Here’s how it works:

1) The visitor types the value in the INPUT

2) The value gets verified through AJAX by making a call to your custom PHP validator

3) If the response is equal with 1 then the field is validated, otherwise an error is shown (the one you set when enabling the custom validator).

How to setup the custom validation?

Here’s a step by step example:

1) Add the field you need by using the “Add Field” button and set its name to “afp_email_address”.

2) Create an empty .PHP file and upload it to /ajax-form-app/includes/check/custom-validation/. (choose an easy name for reference: e.g. verify-email.php).

2) Go to the “Edit” page for the field you’ve just added (e.g. its name is “E-Mail”).

3) Click “+ Add Validation Type” and select ‘Custom’ from the type list.
Add Custom Validation to Field

4) Click “Add Validator”.

5) Now you just need to edit ‘verify-email.php’. All the form’s post data is sent to that file so you can basically use other fields’ values.

Let’s suppose you have to check if the email exists in a foreign database
<?php
if(!empty($_POST)) {
// include files
// verify email if it exists in the database (you can get it through $_POST['afp_email_address'] in this example).

// if it does make sure the output is 1, example:

if($condition_is_met) {
echo 1;
}
}
?>


Leave a Reply

Help us improve the wiki Send Your Comments

Optimization WordPress Plugins & Solutions by W3 EDGE