Form Options

The following form methods are available to set form attributes.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
// 'post' is the default method
$form = new \Vespula\Form\Form();

// Set automatic line feeds
$form->autoLf();

// Set the method explicitly to one of post or get
$form = new \Vespula\Form\Form('get');

// Override the contructor's method attribute
$form->method('get|post');

// Set the form action
$form->action('/some/uri');

// Set the form name
$form->name('foo');

// Set the form id
$form->id('bar');

// Set the form enctype to multipart/form-data
$form->multipart();

// Set the form class
$form->class('foo-class');

// Finally, you can set any attribute via the attribute() method
$form->attribute('some-attrib', 'some-value');

// These call all be chained together in a fluent way, but remember,
// the begin() method must come last as it does not return the form object.
echo $form->id('my-id')->class('my-class')->action('my-action')->begin();

// Outputs
// <form method="get" id="my-id" class="my-class" action="my-action">

// And be sure the close the form tag after you add elements
echo $form->end();