Skip to content

Instantly share code, notes, and snippets.

@philipdowner
Created April 23, 2013 19:03
Show Gist options
  • Save philipdowner/5446434 to your computer and use it in GitHub Desktop.
Save philipdowner/5446434 to your computer and use it in GitHub Desktop.
Troubleshooting Zebra_Form with password comparison
<?php
function ne_explorer_signup_form() {
//ZF Library
require_once(INCLUDES_DIR.'/lib/zebra_form/Zebra_Form.php');
$form = new Zebra_Form('explorer-signup', 'POST');
$form->add('label', 'label_firstname', 'explorer_firstname', 'Your name');
$field = $form->add('text', 'explorer_firstname');
$field->set_rule(array(
'required' => array('error', 'Name is required'),
'alphabet' => array('.,\'', 'error', 'Letters only please!'),
'length' => array(2, 20, 'error', '20 character max'),
));
$field = $form->add('text', 'explorer_lastname');
$field->set_rule(array(
'required' => array('error', 'Name is required'),
'alphabet' => array('.,\'', 'error', 'Letters only please!'),
'length' => array(2, 20, 'error', '20 character max'),
));
$form->add('label', 'label_username', 'explorer_username', 'Pick a username');
$field = $form->add('text', 'explorer_username');
$field->set_rule(array(
'required' => array('error', 'Username required'),
'alphanumeric' => array('', 'error', 'Numbers and letters only!'),
'length' => array(4, 20, 'error', 'Between 4 and 20 characters'),
));
$form->add('label', 'label_email', 'explorer_email', 'Email Address');
$field = $form->add('text', 'explorer_email');
$field->set_rule(array(
'required' => array('error', 'Email address is required'),
'email' => array('error', 'Not a valid email'),
));
$form->add('label', 'label_password', 'explorer_password', 'Choose a password');
$field = $form->add('password', 'explorer_password');
$field->set_rule(array(
'required' => array('error', 'Password is required'),
'length' => array(7, 0, 'error', 'More than 7 characters, please!'),
));
$form->add('label', 'label_password_confirm', 'explorer_password_confirm', 'Confirm your password');
$field = $form->add('password', 'explorer_password_confirm');
$field->set_rule(array(
'compare' => array('explorer_password', 'error', 'Passwords must match!'),
));
$form->add('label', 'label_captcha', 'explorer_captcha', 'Spam Prevention');
$field = $form->add('captcha', 'explorer_captcha');
$field = $form->add('text', 'explorer_captcha_solution');
$field->set_rule(array(
'required' => array('error', 'Please prove you\'re not a robot!'),
'captcha' => array('error', 'Please try again'),
));
$form->add('submit', 'explorer_submit', 'Create your profile');
//Server side validation
if( $form->validate() ) {
//Form passed validation
ne_process_explorer_signup($_POST);
}
//Show the form
$form->render(INCLUDES_DIR.'/form_templates/form_explorersignup.php');
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment