|
Project Information
Members
|
Based on the ideas behind Drupal's form API, the php formapi is a standalone, easy to use form api that saves lots of coding.
Design Goals
Features
Status
UsageTo define a form, write it in simple yaml: $formapi_define_mytestform = "
title: My test form
fieldset:
label: it's a fieldset
textfield:
label: it's a textfield!
required: TRUE
fieldsetclose:
checkbox:
label: my checkboxing
dropdown:
label: my first dropdown
values:
First item: a
Second item: b
Third item: c
--- this is an inline comment that won't show up in the form.
radiogroup:
id: radiogroup1
title: Make a choice:
values:
The first one: a
The second one: b
selected: TRUE
The final one: c
submitbutton:
label: Send this form along!
";Next, define a function that'll be called when the form is submitted: function formapi_submit_mytestform($values) // the part after formapi_submit_ is the form id.
{
print "<h2>My form was submitted!</h2><p>These are the values we got:</p>";
print_r($values);
return FALSE; // return a path if you want to redirect the user.
}You're done! Now, to show the form, just call: formapi_print("mytestform");To create a page that receives all forms, create a php page and add this: include_once("formapi.php"); // include form api
include_once("myforms.php"); // include all form definitions
formapi_receiveform();All forms will be submitted to this page. It will know what to do because each form has an id. That's it. No more coding needed. |