HomePHP Page 3 - Building a Form to Count Back Links Using Yahoo Inbound Links API
PHP Script Preliminary Form Processing - PHP
In the first part of this three-part series, you learned the guiding concepts and design for building a PHP web application to count back links from unique domains using the Yahoo Site Explorer API. In this part, we will illustrate, in detail, how to do the programming for the PHP Ajax web form and the validation script.
This is the start of the PHP script (yahooapiajax.php) which first receives inputs from AJAX via $_POST. Again at the top of the PHP script, place the following:
<?php
session_start();
This is to let PHP capture the correct captcha answer generated by the captcha script: captcha.php
The first thing the PHP script should do is receive the variables passed as parameters on the AJAX query discussed earlier:
$domainurl =trim($_POST['domainurl']);
$options1 =trim($_POST['options1']);
$options2 =trim($_POST['options2']);
$usercaptchaanswer =trim($_POST['captcha']);
$correctcaptcha = $_SESSION['answer'];
The trim function is used to remove any unnecessary spaces in the user input. $_POST values from the form input are assigned to their respective PHP variables.
The next step is to validate the captcha, and to display an error (as well as terminate the script executing) if the captcha entered does not match the correct answer or f it is entered empty:
if (($correctcaptcha != $usercaptchaanswer) || (empty($usercaptchaanswer))) {
echo 'ERROR: You have not entered captcha code or it is entered incorrectly.';