SlideShare une entreprise Scribd logo
1  sur  17
Forme in Zend framework 3
• Creati modulul Forme
si apoi efectuati toate configurarile necesare.
composer update !!!!!
• Creati directorul
module/Forme/src/Form
si in acesta fisierul MyForm.php
Acesata va reprezenta clasa forma “sablon” in care
vor trebui definite toate controalele ce urmeaza a
fi invocate in vederi.
MyForm.php
<?php
namespace FormeForm;
use ZendFormForm;
// A feedback form model
class MyForm extends Form
{
// Constructor.
public function __construct()
{
parent::__construct('myform');//my_form este numele formei
$this->setAttribute('method', 'post');
//text
$this->add([
'type'=>'text',
'name'=>'nume',
'options'=>[
'label'=>'Nume'
]
]);
//text
$this->add([
'type'=>'text',
'name'=>'prenume',
'options'=>[
'label'=>'Prenume'
]
]);
//password
$this->add([
'type'=>'password',
'name'=>'password',
'options'=>[
'label'=>'Password'
]
]);
//textarea
$this->add([
'type'=>'textarea',
'name'=>'textarea',
'attributes'=>[
'rows'=>'5',
'cols'=>'30',
],
'options'=>[
'label'=>'Textarea',
]
]);
//radio
$this->add([
'type'=>'radio',
'name'=>'radio',
'options'=>[
'label'=>'Choose: ',
'value_options'=>[
'0'=>'Negruzzi',
'1'=>'National',
'2'=>'Informatica',
],
]
]);
//checkbox1
$this->add([
'type'=>'checkbox',
'name'=>'check1',
'options'=>[
'label'=>'Iasi',
'check_value'=>'Iasi',
'uncheck_value'=>'0'
]
]);
//checkbox2
$this->add([
'type'=>'checkbox',
'name'=>'check2',
'options'=>[
'label'=>'Bucuresti',
'check_value'=>'Bucuresti',
'uncheck_value'=>'0'
]
]);
//checkbox3
$this->add([
'type'=>'checkbox',
'name'=>'check3',
'options'=>[
'label'=>'Cluj',
'check_value'=>'Cluj',
'uncheck_value'=>'0'
]
]);
//select
$this->add([
'type'=>'select',
'name'=>'dropdown',
'options'=>[
'label'=>'Choose: ',
'value_options'=>[
'0'=>'Negruzzi',
'1'=>'National',
'2'=>'Informatica',
],
]
]);
//list select
$this->add([
'type'=>'MonthSelect',
'name'=>'month',
'options'=>[
'label'=>'Select a month and a year. ',
'min_year'=>'2000',
]
]);
//submit
$this->add([
'type'=>'submit',
'name'=>'submit',
'attributes'=>[
'value'=>'Save'
]
]);
}
}
module/Forme/view/forme/index/index.phtml
<?php
$title="Form controls";
$this->headTitle($title);
?>
<h1><?php echo $this->escapeHtml($title);?></h1>
<?php
$form=$this->form;
//$form->setAttribute('action',$this->url('my_form',['action'=>'show']));
$form->prepare();
echo $this->form()->openTag($form);
echo $this->formRow($form->get('nume'));
echo '<br/>';
echo $this->formRow($form->get('prenume'));
echo '<br/>';
echo $this->formRow($form->get('password'));
echo '<br/>';
echo $this->formRow($form->get('textarea'));
echo '<br/>';
echo $this->formRow($form->get('radio'));
echo '<br/>';
echo $this->formRow($form->get('check1'));
echo $this->formRow($form->get('check2'));
echo $this->formRow($form->get('check3'));
echo '<br/>';
echo $this->formRow($form->get('dropdown'));
echo '<br/>';
echo $this->formRow($form->get('month'));
echo '<br/>';
echo $this->formSubmit($form->get('submit'));
echo '<br/>';
echo $this->form()->closeTag();
?>
module/Forme/src/Controller/IndexController.php
<?php
namespace FormeController;
use ZendMvcControllerAbstractActionController;
use ZendViewModelViewModel;
class IndexController extends AbstractActionController
{
public function indexAction()
{
$form=new FormeFormMyForm();
return new ViewModel(['form'=>$form]);
}
}
module/Forme/config/module.config.php
namespace Forme;
use ZendRouterHttpLiteral;
use ZendRouterHttpSegment;
use
ZendServiceManagerFactoryInvokableFactory;
…………………………….
……………………………..
'forme' => [
'type' => Segment::class,
'options' => [
'route' => '/forme[/:action]',
'defaults' => [
'controller' => ControllerIndexController::class,
'action' => 'index',
],
…………………………………
'view_manager' => [
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => [
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'forme/index/index' => __DIR__ . '/../view/forme/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
],

Contenu connexe

Plus de Razvan Raducanu, PhD

Plus de Razvan Raducanu, PhD (20)

3. trimiterea datelor la vederi
3. trimiterea datelor la vederi3. trimiterea datelor la vederi
3. trimiterea datelor la vederi
 
2.routing in zend framework 3
2.routing in zend framework 32.routing in zend framework 3
2.routing in zend framework 3
 
1. zend framework intro
1. zend framework intro1. zend framework intro
1. zend framework intro
 
18. images in symfony 4
18. images in symfony 418. images in symfony 4
18. images in symfony 4
 
17. delete data
17. delete data17. delete data
17. delete data
 
16. edit data
16. edit data16. edit data
16. edit data
 
15. view single data
15. view single data15. view single data
15. view single data
 
14. add data in symfony4
14. add data in symfony4 14. add data in symfony4
14. add data in symfony4
 
13. view data
13. view data13. view data
13. view data
 
12.doctrine view data
12.doctrine view data12.doctrine view data
12.doctrine view data
 
11. move in Symfony 4
11. move in Symfony 411. move in Symfony 4
11. move in Symfony 4
 
10. add in Symfony 4
10. add in Symfony 410. add in Symfony 4
10. add in Symfony 4
 
9. lower in Symfony 4
9. lower in Symfony 49. lower in Symfony 4
9. lower in Symfony 4
 
8. radio1 in Symfony 4
8. radio1 in Symfony 48. radio1 in Symfony 4
8. radio1 in Symfony 4
 
7. copy2 in Symfony 4
7. copy2 in Symfony 47. copy2 in Symfony 4
7. copy2 in Symfony 4
 
6.copy text
6.copy text6.copy text
6.copy text
 
5.hello popescu2
5.hello popescu25.hello popescu2
5.hello popescu2
 
4.hello popescu
4.hello popescu4.hello popescu
4.hello popescu
 
1.symfony 4 intro
1.symfony 4 intro1.symfony 4 intro
1.symfony 4 intro
 
23.simple login with sessions in laravel 5
23.simple login with sessions in laravel 523.simple login with sessions in laravel 5
23.simple login with sessions in laravel 5
 

4. forme in zend framework 3