Home arrow AJAX & Prototype arrow Page 4 - Completing a User-Defined CSS Website with PHP

The PHP Final Validation Condition and Output - AJAX

In the first part, you learned about CSS and some basic tips/techniques for using the slider to display colors. In this part, we will discuss how we are going to write our AJAX and PHP scripts to make our user-defined CSS website.

TABLE OF CONTENTS:
  1. Completing a User-Defined CSS Website with PHP
  2. Attaching the AJAX Request Function to the Form
  3. The PHP Script Details (CSS.PHP)
  4. The PHP Final Validation Condition and Output
By: Codex-M
Rating: starstarstarstarstar / 5
October 05, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Now that we have prepared all the validation statements, if the input passes the validation, it will output the requested CSS/Style revision. If not, it will end the script execution. The PHP script will be:

if (($backgroundcolorcount=7) && ($fontcolorcount=7) && ($firstbackgroundcolor='#') && ($firstfontcolor='#') && ctype_alnum($alnumbackgroundcolor) && ctype_alnum($alnumfontcolor)) {

//valid inputs, process data

echo $first;

echo '<style type="text/css">'. "n";

echo 'body{ color:'.$fontcolor.';background:'.$backgroundcolor.';}'. "n";

echo '</style>'. "n";

}

else {

//Invalid inputs, end script

die();

}

Note that the alphanumeric validation above is carried out by the ctype_alnum function. Combining all scripts, the completed script for css.php will be:

<?php

if ((!(empty($_POST["backgroundcolor"]))) && (!(empty($_POST["fontcolor"])))) {

//POST field not empty, process data

$backgroundcolor = trim($_POST["backgroundcolor"]);

$fontcolor=trim($_POST["fontcolor"]);

//start of validation

//count characters

$backgroundcolorcount= strlen($backgroundcolor);

$fontcolorcount= strlen($fontcolor);

//grab the first character of the input

$str1 = $backgroundcolor;

$str2 = $fontcolor;

$firstbackgroundcolor = $str1[0];

$firstfontcolor = $str2[0];

//remove # for alphanumeric validation

$alnumbackgroundcolor = substr($backgroundcolor, -6);

$alnumfontcolor = substr($fontcolor, -6);

//validation condition

if (($backgroundcolorcount=7) && ($fontcolorcount=7) && ($firstbackgroundcolor='#') && ($firstfontcolor='#') && ctype_alnum($alnumbackgroundcolor) && ctype_alnum($alnumfontcolor)) {

//valid inputs, process data

echo $first;

echo '<style type="text/css">'. "n";

echo 'body{ color:'.$fontcolor.';background:'.$backgroundcolor.';}'. "n";

echo '</style>'. "n";

}

else {

//Invalid inputs, end script

die();

}

}

else {

//POST field empty, end script

die();

}

?>

Other application notes

You can download and see the entire application. Note that this application only extends to customization of vital styling elements (font color and the background color). However, by updating and improving the script you can extend its capabilities not only to customization of font and background colors, but other CSS elements as well, such as font size, font type, etc.



 
 
>>> More AJAX & Prototype Articles          >>> More By Codex-M
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

AJAX & PROTOTYPE ARTICLES

- Best AJAX Tutorials for Forms
- The Best AJAX Tutorials
- 8 Great Ajax Tutorials
- Using Ajax and jQuery
- Using Ajax and jQuery with HTML Forms
- Ajax.org Offers Cloud9 IDE for JavaScript
- Java Technologies Provider ICEsoft Releases ...
- Using Recaptcha in AJAX Prototype Framework ...
- Google's Closure Compiler Service API: Addit...
- Installing Google Web Toolkit: Introducing t...
- Google's Closure Compiler Service API: Displ...
- Google's Closure Compiler Service API: Deliv...
- Google's Closure Compiler Service API: the A...
- Google's Closure Compiler Service API: the S...
- Google's Closure Compiler Service API: Optim...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: