Location: PHPKode > projects > chillyCMS > chillyCMS/core/formtest.php
<?php
define('DOIT',true);
define('_JEXEC',true);
require_once('../core/session.backend.include.php');

/////////////////////////////////////////////////
// Building the form			       //
/////////////////////////////////////////////////

//The form itself
//($action='',$method='post',$name='',$msggood='',$msgbad='',$compulsorynotice='',$showaftersuccess=true)
$f = new Form('','post','Demoform','Thank you!','Error...','Compulsory field',true);

//Inputfields
//($type,$name,$text=false,$value=false,$compulsory=false,$check=false,$size=false,$maxlength=false,$cols=false,$rows=false,$id=false,$class=false,$title=false,$errorhint=false,$javascript=false)
$f->addInput('text','textinput','Text',false,true,array('/^.*$/','Everything allowed :)'),12,10,false,false,'myid','myclass','mytitle',array('You need to enter something','below'));
$f->addInput('text','min','Min',1,true,array('/^[0-9]*$/','Only numbers'),5,1,false,false,'myid0','myclass','mytitle','Something went wrong...');
$f->addInput('text','max','Max',5,true,array('/^[0-9]*$/','Only numbers'),5,1,false,false,'myid1','myclass','mytitle','Something went wrong...');
$f->addInput('textarea','textareainput','Textarea','Enter something',false,false,false,false,20,5,'myid2','myclass','mytitle',array('You need to enter something','above'));
$f->addInput('hidden','hiddeninput',false,'lalala');
$f->addInput('password','passwordinput','Password','123',true,array('/^\b123\b$/','Please enter 123'),false,false,false,false,'myid3','myclass','mytitle',array('Is this a good password???','below'));

//Selectfields
//($name,$text,$options,$compulsory=false,$selected=false,$size=1,$multiple=false,$id=false,$class=false,$title=false,$errorhint=false,$javascript=false)
$f->addSelect('singleselect','Select single',array(1=>'Option1',2=>'Option2'),false,2,1,false,'myid3','myclass','mytitle',false);
$f->addSelect('multiselect',"Select multi",array(1=>'Salmon',2=>'Mushrooms',3=>'Salami',4=>'Cheese',5=>'Garlic'),false,array(2,5),5,true,'myid4','myclass','mytitle',false);

//Choicefields
//($type,$name,$text,$options,$compulsory=false,$selected=false,$id=false,$class=false,$title=false,$errorhint=false,$javascript=false)
$f->addChoice('checkbox','checkboxes','Checkboxes',array(1=>'Extra Cheese',2=>'Extra Tomato sauce',3=>'Cheezy crust'),false,array(1,3),'myid5','myclass','mytitle',false);
$f->addChoice('radio','radiobuttons','Radiobuttons',array(1=>'American',2=>'PanPizza',3=>'Stone oven'),false,3,'myid6','myclass','mytitle',false);

//File
//($name,$text=false,$compulsory=false,$check=false,$size=false,$accept=false,$id=false,$class=false,$title=false,$errorhint=false,$javascript=false)
$f->addFile('myfile','File',false,false,50);

//Textrow
//($name,$text=false,$longtext=false,$size=1,$id=false,$class=false,$title=false,$javascript=false)
$f->addTextrow('mytextrow','Text','Lorem ipsum dolor sit amet...',1);

//Captcha
//($name,$text=false,$id=false,$class=false,$title=false,$errorhint=false)
$f->addCaptcha('recaptcha');

//Buttons
//($type,$name,$text=false,$value=false,$link=false,$id=false,$class=false,$title=false,$javascript=false)
$f->addButton('submit','submit',false,'Abschicken');
$f->addButton('reset','reset',false,'Zur&uuml;cksetzen');
$f->addButton('jsprint','jsprint','Drucken');
$f->addButton('jsback','jsback','Zur&uuml;ck mit JS');
$f->addButton('back','back','Zur&uuml;ck ohne JS');
$f->addButton('reload','reload','Neu laden');

/////////////////////////////////////////////////
// Handling				       //
/////////////////////////////////////////////////

//first and ONLY ONCE get errors
$f->getErrors();

//the get general form error message
$msg = $f->getMsg();

//get values to compare
$myvalues = $f->getCleanValues('html');

//check values that depend on each other
if ($myvalues['max'] < $myvalues['min']) {
	//overwrite error message
	$msg = array('Min must be smaller than max!','bad');
	//set error on desired field(s)
	$f->setError('max');
	$f->setError('min');
}

$page->debug($f->errors);

//if there were no errors proceed with whatever
if ($f->sent && is_array($f->errors) && sizeof($f->errors)<1) {
	$doit = true;
} else {
	$doit = false;
}

//do it :)
if ($doit) {
	$mydbvalues = $f->getCleanValues('db');
	$page->debug($mydbvalues);
}

//render form
$myform = $f->render('table');

//build your page
$page->print_head();
$page->add($myform);
$page->print_body($msg);
?>
Return current item: chillyCMS