Parse error: syntax error, unexpected '2' (T_LNUMBER) in /var/www/agiletoolkit.org/_/codepad/atk4-addons/documenting/lib/View/Example.php(60) : eval()'d code on line 1

Parse error: syntax error, unexpected 'types' (T_STRING) in /var/www/agiletoolkit.org/_/codepad/atk4-addons/documenting/lib/View/Example.php(60) : eval()'d code on line 1

Parse error: syntax error, unexpected '1' (T_LNUMBER) in /var/www/agiletoolkit.org/_/codepad/atk4-addons/documenting/lib/View/Example.php(60) : eval()'d code on line 1

Parse error: syntax error, unexpected '2' (T_LNUMBER) in /var/www/agiletoolkit.org/_/codepad/atk4-addons/documenting/lib/View/Example.php(60) : eval()'d code on line 1

Parse error: syntax error, unexpected '3' (T_LNUMBER) in /var/www/agiletoolkit.org/_/codepad/atk4-addons/documenting/lib/View/Example.php(60) : eval()'d code on line 1
Agile Toolkit

Basic Form Example

Form is a fundamental component of any web application. Agile Toolkit greatly simplifies form creation.

SOURCE

$form=$page->add('Form');
$form->addField('line','name');
$form->addField('line','surname');
$form->addSubmit();

if($form->isSubmitted()){
  $form->js()->univ()->alert('Thank you, '.
    $form->get('name').' '.$form->get('surname'))->execute();
}

  
Demo
SOURCE
example 2
$f=$page->add('Form');

// email field
$f->addField('line','email')
    ->validateNotNull()
    ->validateField('filter_var($this->get(), FILTER_VALIDATE_EMAIL)')
    ;

// Submit handling    
$f->addSubmit('Check email');
if($f->isSubmitted()){
    $f->js()->univ()->alert('Email '.$f->get('email').' is valid')->execute();
}

// Application is safe from arbitary code injection, but validate input at will

  
Demo
The example was executed successfully, but did not produce any output
example 3
SOURCE

$f=$page->add('Form');

// using multiple validations on a same field
$f->addField('line','username')->validateNotNull()
    ->validateField('preg_match("/^[a-z]+$/",$this->get())')
    ->validateField('strlen($this->get())>=6','Too short')
    ->validateField('20>=strlen($this->get())','Too long');

$f->addField('password','pasword')->validateNotNull();
$f->addSubmit('Login');

if($f->isSubmitted()){
    $f->js()->univ()->alert('[Demo] Login Successful')->execute();
}

  
Demo

Form Elements

There are many field types you can use with form. In addition you can add your own field types or use add-on which may provide additional types.

SOURCE
field types
$form=$page->add('Form');
$form->addComment('This form shows all sorts of fields you can use by default');
$form->addField('Line','line');
$form->addField('Password','password');
$form->addField('Checkbox','checkbox');
$form->addField('Dropdown','dropdown');
$form->addField('CheckboxList','checkboxlist');
$form->addField('Radio','radio');
$form->addField('DatePicker','date');
$form->addField('Text','text');

$form->addSeparator();
$form->addField('Slider','Slider');
$form->addField('upload','upload');

$form->addSeparator('Here are some variations in how you can use fields');
$form->addField('Search','Search');
$form->addSubmit();

  
Demo
The example was executed successfully, but did not produce any output

Use with Model

The most convenient way to use form is to have it's fields populated from a Model.

SOURCE
model 1
$form = $page->add('Form');
$form->setModel('Employee');
$form->addSubmit();

  
Demo
The example was executed successfully, but did not produce any output
SOURCE
model 2
$f = $page->add('Form');

// defining arary of fields to show and sequence order
$f->setModel('Employee',array('name'));

  
Demo
The example was executed successfully, but did not produce any output
SOURCE
model 3
$model = $page->add('Model_Employee');
$model->addCondition('salary','<=',3000);

$f=$page->add('Form');

$f->setModel($model,array('name','salary'));
$f->getElement('salary')->setFieldHint('Must not exceed 3000');
$f->addSubmit();

$f->onSubmit(function($f){
	try {
		$f->update()->js()->univ()->successMessage('Saved with id='.$f->model->id)->execute();
	}catch(Exception $e){
		$f->js()->univ()->alert('Failed to add record')->execute();
	}
});


  
Demo
The example was executed successfully, but did not produce any output