Skip to content
robik edited this page May 25, 2012 · 2 revisions

Downloading

There are 2 ways of downloading QForm:

  • Git

    You can download QForm by using clone command:

     $ git clone https://robik@github.com/robik/QForm.git
    
  • ZIP

    You can also get QForm source in ZIP format.

    • Visit this page and press

    • Click ZIP button that can be found in upper part of page.

Installation

Copy contents of lib/ dir to your project's directory. If you don't have autoloader, you will need to include all of the QForm files.

First code

Let's start from creating Builder instance. Builder is helper class that helps creating forms with clear syntax. This way is not only you can build forms, but it's easy enough to start with :)

# 1
$builder = new QForm\Builder('/user/login', 'post');

#2
echo $builder->getForm()->render();

Lets start from explaining the above example line by line:

1. Creates new Builder instance. Parameters passed are:

  • Form action (where to send form)

  • Form method, can be ommited. By default it's get

2. Returns built form and renders it.

If you don't like using builder, you can create form using alternative way:

$form = new QForm\Control\Form('/user/login', 'post');
echo $form->render();

Parameters are the same as in Builder, but adding form members using this way is diffrent, more info soon :)

Adding members

After creating builder instance, you can continue to adding form members, for example adding textbox is something like:

$builder->textbox("name");

Or without builder, it would be something like:

$form->addChild(new TextBox("name"));

Note: QForm\Builder contains getForm() method, which returns QForm\Control\Form instance. Allowing you to mix above techniques.

Labeling input

TextBox without label is useless, to be honest. User don't know what it is for and confuses him. To avoid that, Textbox should be labelled/named/described. It can be done in few ways:

  1. Adding text before input

  2. Add <label> and link it with input

The first way is easiest, but second is suggested. Both can be done with QForm, first way would be:

$builder->text("Login:");
$builder->textbox("login");

And second, using labels:

$builder->label("login", "Login:");
$builder->textbox("login", array("id"=>"login"));

QForm\Builder::label as first argument takes id of control that should will be labelled, second parameter takes label text.

Note: $builder->text() creates new QForm\Control\Text, which is not really a control. It is rendered as normal text.

Next: QForm design