Helix Installation   Getting Started   Reference Documentation   Global Functions   Quick Start
Getting StartedHelpful ResourcesAsk questions on the Help ForumRead the User GuideBrowse the Reference DocumentationSubscribe to the Helix Mailing ListLearning HelixAdvanced Topics

Using Forms

Using forms in your web application is very simple with the Helix form class and the form input classes  You can create any of the standard HTML form input elements using the Helix form classes like:

  • form - A form element
  • input - An input element that can be one of the standard HTML input types: text, password, checkbox, radio, submit, reset, file, hidden, image, button
  • textarea - A multiple-line text input box
  • button - A button element
  • select - A dropdown box
  • option - An option in a dropdown box

There are also more useful custom form controls that are made from a combination of the simple form controls like:

  • checklist - A list of checkbox items that are sent to the server as an array of values
  • radiolist - A list of radio button items
  • doubleselect - Two multiple-select boxes side-by-side with arrow controls in the middle to move choices back and forth.
  • dateselect - A set of three dropdown boxes side-by-side with the month name, day and year that is passed to the server as an array with 3 keys named month, day and year.
  • timeselect - A set of three dropdown boxes side-by-side with the hour, minute and am/pm that is passed to the server as an array with 3 keys named hour, minute and ampm.

Displaying Forms In Helix

Displaying a form on a page is handled by the form classes mentioned above.  Just open the form tag, add some form inputs, then close the form tag.

See the code below for an example of how to use a form on a page:

// Open the form element and set the form action attribute
form::open("login-form",WEBROOT "test-page");
// Add some text boxes
// Add a button with a function to call in the codebehind
$button = new button("Click Me","btn-login-form","authenticate_user");
// Close the form element

The code above creates a form with id login-form, two text boxes for a username and password, and a button to submit the form and call a function in the codebehind for that page.  The second parameter to the input::open() method that defines the username field tells Helix what options to use as the value to that input.  The alt() method takes 1 or more parameters and returns the value of the first non-null parameter.  The reqval() method takes an array key as a parameter and returns a value from the PHP $_REQUEST[] array if the key exists.  Using these methods together has the effect of showing the last posted value in the text box, or nothing if there is no posted value.  The third parameter passed to the input::open() method tells Helix what to use for the type attribute.

The third parameter to the new button() constructor is a name of a function in the codebehind file for that page.  The button object will insert a hidden input into the form with an input name of f and value of the codebehind function name.  When this form is submitted, the form input values will be passed to the server and the codebehind function named authenticate_user will be called.

Get Helix PHP Framework at SourceForge.net. Fast, secure and Free Open Source software downloads