PHP Classes

File: Form/example.php

Recommend this page to a friend!
  Packages of Arkadiusz Malinski   am_Forms   Form/example.php   Download  
File: Form/example.php
Role: Example script
Content type: text/plain
Description: Example of using this class with Smarty templates
Class: am_Forms
Generate and validate Web forms
Author: By
Last change: 1
Date: 20 years ago
Size: 1,422 bytes
 

 

Contents

Class file image Download
<?
/*
 * Example using class Form with Smarty template system.
 * This form creates four field and validate them.
 */

/*
 * File: index.php
 */

    require_once('class.form.php');
    require_once('Smarty/Smarty.class.php');
    
    try {
        $_form = new Form("Register", "POST", "index.php");
        $accountForm = array(
            "Begin"            =>    $_form->start().$_form->input("hidden", "mode", "account"),
            "Fields"        =>    array(
                "name"        =>    $_form->input("text", "name", "John Smith"),
                "phone"        =>    $_form->input("text", "phone", "+55 555 5555 55 55"),
                "email"        =>    $_form->input("text", "email", "user@domain.com"),
                "email2"    =>    $_form->input("text", "email2", "user@domain.com")
            ),
            "js_check"        =>    $_form->sprawdzPoprawnosc(array(
                    "name"        => "REQURED",
                    "phone"        => "REQUIRED|VALID_TEL",
                    "email"        => "REQUIRED|VALID_EMAIL",
                    "email2"    => "REQUIRED|VALID_EMAIL|EQUAL_TO_EMAIL"
                )
            ),
            "send_button"    =>    $_form->input("submit", "ChangeBtn", "Change All"),
            "End"            =>    $_form->stop()
        );

        $_smarty->assign('accountForm', $accountForm);
        $_smarty->display('index.tpl');
        
    } catch (Exception $err) {
        $_arError['message']     = $err->getMessage();
        $_arError['filename']    = $err->getFile();
        $_arError['line_no']    = $err->getLine();
        $_arError['trace']        = $err->getTrace();
        $_smarty->assign('error', $_arError);
        $_smarty->display('error.tpl');
    }

?>