Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Maurice Courtois  >  cm forms  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: An example script
Class: cm forms
Validate and processing Web forms
Author: By
Last change: Version 1.5
Date: 2004-11-15 07:51
Size: 9,306 bytes
 

Contents

Class file image Download
<?php

// Copyright CM Technology
/***************************************************************************
 *            example.php
 *
 *  Mon June 06 15:10:06 2004
 *  Copyright  2004  Cnet com - Maurice Courtois
 *  maurice@phmarket.com
 ****************************************************************************/
 /*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Library General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

// Include

require "forms.class.inc";

//
// Affecting the variable
//


// The form declaration
// create a $field[$num] for each field of your form. The 'name' indexed is the key, need to be the same of the declaration you have made on your forms.
//
// Template of a typical field.
//
// $field[0]['name'] = "name";         <--- This is the name of your field
// $field[0]['tr_type'] = "name";        <--- This is the type of validation you want to made on your field
// $field[0]['regex1'] = "";        <--- You can write any php code here for the validation // optional
// $field[0]['min_limit'] = 1;        <--- To overpass the minimum value of a type of field, if you want a mandatory field you just need to write 1 here // optional
// $field[0]['max_limit'] = 3;        <--- To overpass the maximum value of a type of field // optional

$field[0]['name'] = "name";
$field[0]['tr_type'] = "name";
$field[0]['regex1'] = "";

$field[1]['name'] = "company";
$field[1]['tr_type'] = "name";
$field[1]['regex1'] = "";
$field[1]['min_limit'] = 0;

$field[2]['name'] = "email";
$field[2]['tr_type'] = "email";
$field[2]['regex1'] = "";

$field[3]['name'] = "phone";
$field[3]['tr_type'] = "intphone";
$field[3]['type'] = "varchar";
$field[3]['regex1'] = "";

$field[4]['name'] = "fax";
$field[4]['tr_type'] = "intphone";
$field[4]['regex1'] = "";
$field[4]['min_limit'] = 0;

$field[5]['name'] = "comments";
$field[5]['tr_type'] = "text"// For .,'etc...
$field[5]['regex1'] = "";
$field[5]['max_limit'] = 2500;

// Affect the variable for the status msg.

$contact_form2[0]="You need to correct this error : ";
$contact_form2[1]="You made some errors on this form : ";
// Remember that : The index 0 of $class_forms_validate_error is for key only. Stay this empty.
$class_forms_validate_error['name'][0] = "";
$class_forms_validate_error['name'][1] = "You need to enter a valid name";
$class_forms_validate_error['name'][2] = "You have tried to enter to much data on the field name";
$class_forms_validate_error['company'][0] = "";
$class_forms_validate_error['company'][1] = "You need to enter a valid company name";
$class_forms_validate_error['company'][2] = "You have tried to put to much data on the field compagny";
$class_forms_validate_error['email'][0] = "";
$class_forms_validate_error['email'][1] = "You need to enter a valid email address";
$class_forms_validate_error['email'][2] = "You have tried to enter to much data on the field email";
$class_forms_validate_error['phone'][0] = "";
$class_forms_validate_error['phone'][1] = "You need to enter a valid phone number ex : (555-555-5555)";
$class_forms_validate_error['phone'][2] = "You have tried to enter to much data on the field Phone.";
$class_forms_validate_error['fax'][0] = "";
$class_forms_validate_error['fax'][1] = "You need to enter a valid fax number ex : (555-555-5555)";
$class_forms_validate_error['fax'][2] = "You have tried to enter to much data on the field Fax";
$class_forms_validate_error['comments'][0] = "";
$class_forms_validate_error['comments'][1] = "Please give us more details on your comment";
$class_forms_validate_error['comments'][2] = "You have tried to enter to much data on the comment field.";

$class_forms_validate_success['success'][0] = "\n<br />The form has been sent sucessfully";

// The email message.
// Please customize it.


if(isset($_SERVER['HTTP_REFERER']))
{
    
$referer $_SERVER['HTTP_REFERER']; // Detection of the hostname of your website
}
else
    
$referer "example_script.com"// Your host (sometime with apache2 the autodetection failled).
$email[0] = "email"// Type of record (at this time only email is functionnal)
$email[1][0] = "maurice@phmarket.com"// Your email address
$email[1][1] = "A client filled up the forms on ".$referer// The subject of the message
$email[1][2] = "
Below is somes informations about the client

The ip of the client : "
.$_SERVER['REMOTE_ADDR']."


See below what the client have filled"
// The message itself
$email[1][3] = "End of the form\n"// Just a ending line.

// End of the email.

// End of variable affectation



//
// Main
//

// You have nothing to change here.


// $obj = new forms_validate($field_array, "method", "name of the form");
$forms_validate = new forms_validate($field"POST""contact");

//
// Affecting the status msg from the class error line
//


// $var = $forms_validate->process_err_msg($array_the_first_word_of_the_status_msg, $array_the_error_msg, $array_the_success_msg);

$error_line $forms_validate->process_err_msg($contact_form2,$class_forms_validate_error$class_forms_validate_success);



// sending the email

$process = new forms_process($email$field);


//
// End of main
//


// You can write your web page after that.
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Form</title>
<meta name="description" content="">
<meta name="keywords" lang="en" content="">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="Content-Language" content="en-us">
<meta name="reply-to" content="you@youremail.com">
<meta name="category" content="">
<meta name="robots" content="index, follow">
<meta name="distribution" content="global">
<meta name="revisit-after" content="7 days">
<meta name="author" lang="en-us" content="">
<meta name="copyright" content="">
<meta name="expires" content="never">
<meta name="Date-Creation-yyyymmdd" content="20040603">
<style type="text/css">
font.error {
font-size : 12px;
font-family : Verdana, Helvetica, Sans-Serif;
color: #FF4747;
}
</style>
</head>

<body bgcolor='#ffffff'>





<br />
<table align='center' width='300'>
    <tr>
        <td align='center'><font class='error'>
        <?php
// STATUS MSG OF THE FORMS
printf("%s\n<br />"$error_line);
?>
        </font>
        </td>
    </tr>
</table>
<br />
<table align='center'>
    <tr>
        <td align='center'>Contact form
<form action='example.php' method='post'>
            <table width='350' border='0' align='center'>
                <tr>
                    <td align='left' width='100'><?php echo $forms_validate->search_key("name"); ?>Name : </td>
                    <td align='left' width='250'><input name='name' size='22' maxlength='22' value="<?php echo htmlentities($forms_validate->fill("name"));?>"></td>
                </tr>
                <tr>
                    <td align='left' width='100'><?php echo $forms_validate->search_key("company"); ?>Company : </td>
                    <td align='left' width='250'><input name='company' size='22' maxlength='22' value="<?php echo htmlentities($forms_validate->fill("company"));?>"></td>
                </tr>
                <tr>
                    <td align='left' width='100'><?php echo $forms_validate->search_key("email"); ?>Email : </td>
                    <td align='left' width='250'><input name='email' size='22' maxlength='50' value="<?php echo htmlentities($forms_validate->fill("email"));?>"></td>
                </tr>
                <tr>
                    <td align='left' width='100'><?php echo $forms_validate->search_key("phone"); ?>Phone : </td>
                    <td align='left' width='250'><input name='phone' size='22' maxlength='22' value="<?php echo htmlentities($forms_validate->fill("phone"));?>"></td>
                </tr>
                <tr>
                    <td align='left' width='100'><?php echo $forms_validate->search_key("fax"); ; ?>Fax : </td>
                    <td align='left' width='250'><input name='fax' size='22' maxlength='22' value="<?php echo htmlentities($forms_validate->fill("fax"));?>"></td>
                </tr>
                <tr>
                    <td colspan='2' align='center' width='350'><?php echo $forms_validate->search_key("comments");?>Comments : <br />
                    <textarea name='comments' rows='6' cols='40'><?php echo htmlentities($forms_validate->fill("comments"));?></textarea>
                    </td>
                </tr>
                <tr>
                    <td colspan='2' align='center' width='350'>
                        <table width='350'>
                            <tr>
                                <td align='right' width='175'>
                                <!--- hiden input
                                The status of the form field. You need to keep this
                                -->
                                <!-- !!!!!!!!! CHANGED HERE !!!!!!!!!!! -->
                                <input type='hidden' name='state' value='<?php echo $forms_validate->change_state(); ?>'>
                                <!-- End hiden input -->
                                <input type='submit' name='submit' value='Send'></td>
                                <td align='left' width='175'><input type='reset' name='reset' value='Reset'></td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
            </form>
        </td>
    </tr>
</table>




</body>
</html>