Skip to content

Instantly share code, notes, and snippets.

@netcarver
Created April 4, 2012 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netcarver/52c5ba2d64291310a3a2 to your computer and use it in GitHub Desktop.
Save netcarver/52c5ba2d64291310a3a2 to your computer and use it in GitHub Desktop.
Example form using public form builder...
<?php
require_once( $_SERVER['DOCUMENT_ROOT'] . "/site/forms/forms.php" );
$f = Form('Contact', './')
->setRenderer( fxForm::BASIC ) // Choose the renderer to use to convert this to HTML(5)
// I also plan to implement a renderer for twitter's bootstrap and other renderers can
// be plugged in as needed.
->onSuccess('MySuccessHandler') // Which routine gets called on successful submission and validation?
->add( Fieldset('About you...')
->add( Input('name', 'Your name')->required() ) // Creates a text input with client + server validation
->add( Email('email', 'Your email address')->required() ) // Creates an email input with client + server validation
->add( URL('url', 'Your Website') ) // Same here but for a url
)
->add( Fieldset('Your message...')
->add( Textarea('msg', 'Your message to us')->required()->maxlength(1000) )
)
->add( Fieldset('Legal stuff...')
->add( Checkbox('cond', '>I Agree to the terms and conditions.' ) ) // Creates a checkbox with a right-aligned label
)
->add( Submit('Send')->enabledIf('cond.checked') ) // Submit button state is controlled by the checkbox state (client side)
// Of course, on the server side, validation of elements will still take place.
// enabledIf() also allows you to check form element values.
// eg: ->enabledIf('age.value<18')
->process()
;
echo $f;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment