Login   Register  
PHP Classes
elePHPant
Icontem

File: example_big.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Jonas Earendel  >  jForm Validator  >  example_big.php  >  Download  
File: example_big.php
Role: Example script
Content type: text/plain
Description: A big example
Class: jForm Validator
Validate forms with rules defined in form template
Author: By
Last change: Added a link to the new css file.
Date: 1 year ago
Size: 6,285 bytes
 

Contents

Class file image Download
<?php

include_once('class.jForm.php');

$html '
    <label>Radio</label>
    <input id="radio_yes" type="radio" value="2" name="radio" /><label for="radio_yes">Yes</label><br />
    <input id="radio_no" type="radio" value="#1" name="radio" required="required" /><label for="radio_no">No</label> <br />

    <label for="checkbox">Checkbox</label>
    <input id="checkbox" type="checkbox" value="#1" name="checkbox" required="required" /><br />

    <label for="color">Color</label>
    <input id="color" type="color" value="##ffffff" name="color" required="required" /><br />

    <label for="date">Date</label>
    <input id="date" type="date" value="#2011-12-12" name="date" required="required" /><br />

    <label for="datetime">Datetime</label>
    <input id="datetime" type="datetime" value="#2011-12-12T12:12Z" name="datetime" required="required" /><br />

    <label for="datetime-local">Datetime-local</label>
    <input id="datetime-local" type="datetime-local" value="#2011-12-12T12:12" name="datetime-local" required="required" /><br />

    <label for="email">Email</label>
    <input id="email" type="email" value="#john@doe.com!" name="email" required="required" /><br />

    <label for="hidden">Hidden</label>
    <input id="hidden" type="hidden" value="#123" validate="number" name="hidden" required="required" /><br />

    <label for="month">Month</label>
    <input id="month" type="month" value="#1974-12" name="month" required="required" /><br />

    <label for="number">Number</label>
    <input id="number" type="number" value="#2300" max="3000" min="1000" step="100" name="number" required="required" /><br />

    <label for="integer">Integer</label>
    <input id="integer" type="integer" value="#10" max="15" min="5" name="integer" required="required" /><br />

    <label for="tel">Tel</label>
    <input id="tel" type="tel" value="#1-200-234-2343" country="US" name="tel" required="required" /><br />

    <label for="text">Text</label>
    <input id="text" type="text" value="#text" callback="jForm::testCallback" name="text" required="required" /><br />

    <label for="search">Search</label>
    <input id="search" type="search" value="#atext" mustmatch="text" name="search" required="required" /><br />

    <label for="time">Time</label>
    <input id="time" type="time" value="#13:12" name="time" required="required" /><br />

    <label for="url">Url</label>
    <input id="url" type="url" value="#http://www.testsite.com" name="url" required="required" /><br />

    <label for="week">Week</label>
    <input id="week" type="week" value="#2011-W32" name="week" required="required" /><br />

    <label for="range">Range</label>
    <input id="range" type="range" value="#13" max="14" min="4" step="3" name="range" required="required" /><br />

    <label for="creditcard">Creditcard</label>
    <input id="creditcard" type="creditcard" value="#5500000000000004" name="creditcard" required="required" /><br />

    <label for="alphabetic">Alphabetic</label>
    <input id="alphabetic" type="alphabetic" value="#qwerty" minlength="4" maxlength="6" name="alphabetic" required="required" /><br />

    <label for="alphanumeric">Alphanumeric</label>
    <input id="alphanumeric" type="alphanumeric" value="#alphanumeric" name="alphanumeric" required="required" /><br />

    <label for="zipcode">Zipcode</label>
    <input id="zipcode" type="zipcode" value="#1234 AZ" countryelement="country" name="zipcode" required="required" /><br />

    <label for="ipv4">Ipv4</label>
    <input id="ipv4" type="ipv4" value="255.255.255.256" name="ipv4" required="required" /><br />

    <label for="ipv6">Ipv6</label>
    <input id="ipv6" type="ipv6" value="#2001:0db8:0000:0000:0000:0000:1428:07ab" name="ipv6" required="required" /><br />

    <label for="textarea">Textarea</label>
    <textarea name="textarea" id="textarea" cols="45" rows="3" maxlength="10" required="required">#asdfasdfas</textarea><br />

    <label for="country">Select</label>
    <select name="country" id="country" required="required">
        <option value="">Pick a country</option>
        <option value="se">Sweden</option>
        <option value="us">USA</option>
        <option value="nl">Netherlands</option>
        <option value="ch">Switzerland</option>
    </select><br />

    <label for="captcha">Captcha</label>
    <input id="captcha" type="captcha" name="captcha" required="required" /> Enter the text in the image<br />
'
;

//define('LANGUAGE','fr-FR');
define('LANGUAGE','en-GB');
//define('LANGUAGE','sv-SE');

// normally I have the form in a separate file. Better color coding and text-completion
// like so: $form = new jForm($path_and_filename,LANGUAGE);
// But to avoid having too many files I put it in the above variable.
$form = new jForm($html,LANGUAGE);

if(!empty(
$_POST) and $form -> validate($_POST))
{
    
$form->triggerError('The form has passed validation','email');
    
$form->triggerError('The form has passed validation','url');
}

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="<?php echo LANGUAGE?>">
<head>
    <title>jForm php form validation demo!</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script type="text/javascript" src="creditcard.js"></script>
    <script type="text/javascript" src="is.js"></script>
    <script type="text/javascript" src="jquery.watch.js"></script>
    <script type="text/javascript" src="jquery.validate.js"></script>
    <script type="text/javascript" src="jquery.validate.translations.sv-SE.js"></script>
    <script type="text/javascript" src="jquery.validate.translations.fr-FR.js"></script>
    <link rel="stylesheet" type="text/css" href="jform.css" media="screen, projection" />
    <style type="text/css">
        span.validator-status
        {
            background-image: url(?jform-validator-image);
        }
    </style>
    <script type="text/javascript">
        $(function() {
            $("form").validate();    // comment this line if you want to try it without jquery
        });
    </script>
</head>
<body>
<form id="jform" method="post" action="">
    <?php echo $form->html4();     // or you can pass false as a parameter here ?>
    <input type="submit" />
</form>
</body>
</html>