1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Jformer</title>
<link rel="stylesheet" type="text/css" href="lib/jformer.css" />
<script type="text/javascript" src="lib/jquery-1.5.2.min.js"></script>
<script type="text/javascript" src="lib/jformer.js"></script>
</head>
<body>
<div style="width:980px; margin:0 auto">
<?php include("jformer.php"); ?>
<?php // Create the form
// Create the form
$login = new JFormer('loginForm', array(
'submitButtonText' => 'Login',
));
// Create the form page
$jFormPage1 = new JFormPage($login->id.'Page', array(
'title' => '<p>Login Demo</p>',
));
// Create the form section
$jFormSection1 = new JFormSection($login->id.'Section', array());
// Check to see if the remember me checkbox should be checked by default
// Add components to the section
$jFormSection1->addJFormComponentArray(array(
new JFormComponentSingleLineText('username', 'Username:', array(
'validationOptions' => array('required', 'username'),
'tip' => '<p>The demo login is <b>admin</b>.</p>',
)),
new JFormComponentSingleLineText('password', 'Password:', array(
'type' => 'password',
'validationOptions' => array('required', 'password'),
'tip' => '<p>Password is 12345</p>',
)),
new JFormComponentMultipleChoice('rememberMe', '',
array(
array('value' => 'remember', 'label' => 'Keep me logged in on this computer')
),
array(
'tip' => '<p>If a cookie is set you can have this checked by default.</p>',
)
),
));
// Add the section to the page
$jFormPage1->addJFormSection($jFormSection1);
// Add the page to the form
$login->addJFormPage($jFormPage1);
// Set the function for a successful form submission
function onSubmit($formValues) {
$formValues = $formValues->loginFormPage->loginFormSection;
if($formValues->username == 'admin' && $formValues->password == '12345') {
if(!empty($formValues->rememberMe)) {
$response = array('redirect' => 'form.php');
}
else {
$response = array('successPageHtml' => '<p>Login Successful</p><p>We won\'t keep you logged in on this computer.</p>');
}
}
else {
$response = array('failureNoticeHtml' => 'Invalid username or password.', 'failureJs' => "$('#password').val('').focus();");
}
return $response;
}
// Process any request to the form
$login->processRequest();
?>
</div>
</body>
</html> |
Partager