Jump to content

HTML_QuickForm2 Doesn't Pass Validation


RonInNewYork

Recommended Posts

And I'm not sure why. Here's the code:

<?php
function displayPageHeader($pageTitle, $memberArea=false) {

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <title>QuickForm2</title>
    <link rel="stylesheet" type="text/css" href="common.css" />
<style type="text/css">
.error {background: #D33; color:white; padding: 0.2em;}
th {text-align: left; background-color: #bbb;}
th, td {padding: 0.4em;}
tr.alt td{background:#ddd;}
fieldset {border:none;}
ol {list-style:none;}
input, select, textarea {float: none; margin:1em 0 0 0; width:auto;}
div.element {float:right; width:57%;}
div.element label {display:inline; float:none}

</style>
  </head>
  <body>
<h1><?php echo $pageTitle?></h1>
<?php
}

// Load the main class
require_once 'HTML/QuickForm2.php';
require_once 'HTML/QuickForm2/Rule/Required.php';
require_once 'HTML/QuickForm2/Rule/Regex.php';
// Instantiate the HTML_QuickForm2 object
displayPageHeader("QuickForm2");
$form = new HTML_QuickForm2('tutorial', "GET","","", null, true);

// Set defaults for the form elements
$form->addDataSource(new HTML_QuickForm2_DataSource_Array(array(
    'name' => 'Joe User'
)));

// Add some elements to the form
$fieldset = $form->addElement('fieldset')->setLabel('QuickForm2 tutorial example');
$firstName = $fieldset->addElement('text', 'First Name', array('size' => 50, 'maxlength' => 255))
                 ->setLabel('First Name:');
$lastName = $fieldset->addElement('text', 'Last Name', array('size' => 50, 'maxlength' => 255))
                 ->setLabel('Last Name:');
$email= $fieldset->addElement('text', 'email',array('size'=>  30, 'maxlength'=> 30))->setLabel('Enter your email address:');
$fieldset->addElement('submit', null, array('value' => 'Send!'));

// Define filters and validation rules
$firstName->addFilter('trim');
$firstName->addRule('required', 'Please enter your first name');
$lastName->addFilter('trim');
$lastName->addRule('required', 'Please enter your last name');
$email->addRule('required');
$email->addRule(new HTML_QuickForm2_Rule_Regex(
    $email, 'Email should be in proper email format: [email protected]', '/^(?!(??:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(??:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){65,}@)(??:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(??:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22)))*@(??:(?!.*[^.]{64,})(??:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\.){1,126}){1,}(??:[a-z][a-z0-9]*)|(??:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\[(??:IPv6:(??:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(??!(?:.*[a-f0-9][:\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?:?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(??:IPv6:(??:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}|(??!(?:.*[a-f0-9]{5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?:?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}?)))?(??:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(??:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$/iD'));


// Try to validate a form
if ($form->validate()) {
    echo '<h1>Hello, ' . htmlspecialchars($name->getValue()) . '!</h1>';
    exit;
}
else

// Output the form
?>
<div style="width:25em;">
<?php
echo $form;
?>
</div>

</body>
</html>

 

Link to comment
https://forums.phpfreaks.com/topic/235531-html_quickform2-doesnt-pass-validation/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.