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 Luke Rotherfield  >  Nibble forms  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example scripts
Class: Nibble forms
Generate and validate HTML forms with PHP
Author: By
Last change:
Date: 2 years ago
Size: 2,284 bytes
 

Contents

Class file image Download
<?php
  error_reporting
(E_ALL E_STRICT);
  
ini_set('display_errors'1);
  
session_name('nibble');
  
ini_set('session.gc_maxlifetime',30*60);
  
session_set_cookie_params(30*60);
  
session_start();
  include 
dirname(__FILE__).'/nibble-flash-messaging/Flash.class.php';
  
$flash Flash::getInstance();
  
$flash->message('Simple message example');
  
$flash->flashMessage('Message content goes here, 5s lifetime','Message title goes here',5000);
  
$flash->message('Sticky error message','Sticky message',0,true,'error');
  include 
dirname(__FILE__).'/nibble-forms/NibbleForm.class.php';
  
$form NibbleForm::getInstance('''Submit this form','post',true,'flash');
  
$form->username = new Text('Please enter your username'true20'/[a-zA-Z0-9]+/');
  
$form->email = new Email('Please enter your email',false);
  
$form->email->addConfirmation('Please confirm your email');
  
$form->captcha = new Captcha();
  
$form->password = new Password('Please enter your password'11truetrue12);
  
$form->password->addConfirmation('Please confirm your password');
  
$form->checkbox = new Checkbox('Please select one of the following', array(
    
'One' => 'Choice one, dont choose',
    
'car' => 'Choice two',
    
'Choice three',
    
'Choice four'
  
),true,2);
  
$form->select = new MultipleSelect('Please select at least two of the following', array(
    
'One'=>'Choice one',
    
'Choice two',
    
'Choice three'
  
),false,true,2);
  
$form->file = new File('Please upload a file',array('image/png'),true);
  
$form->addData(array(
    
'username' => 'Luke',
    
'radio' => 0,
    
'checkbox' => array(1,'car')
  ));
  if(isset(
$_POST['submit'])){
    if(
$form->validate()){
      echo 
'Valid';
    } else {
      echo 
'Invalid';
    }
  }

?>
<!doctype html>
<html>
  <head>
    
    <title>Example flash messaging</title>
    <script src="http://www.google.com/jsapi" type="text/javascript"></script>
    <script type="text/javascript">google.load("jquery","1");google.load("jqueryui","1");</script>
    <script type="text/javascript" src="nibble-flash-messaging/notice.js"></script>
    <link rel="stylesheet" type="text/css" media="screen" href="nibble-flash-messaging/style.css" />

  </head>
  <body>
  <?php echo $form->render() ?>
  <?php echo $flash->render() ?>
  </body>
</html>