| 
<?php ini_set('display_errors', 1); ?>
<html>
 <head>
 <title>Form Generation</title>
 <script language="JavaScript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
 <script language="JavaScript" src="validation.js"></script>
 <script language="JavaScript">
 var valid = new validate();
 </script>
 <?php
 include('formgeneration.php');     // load the class
 
 // a class the extends formgeneration to add a post submit validation check
 class Myformgeneration extends formgeneration {
 // This is the minimum constructor and is required for the child class.
 public function __construct($class) {
 parent::__construct( $class);
 }
 
 // Overridden funciton
 //
 // Note that this version generates an error. THis was for testing purposes
 // You will want to replace the code in the if ($return == '') block with your real validation
 public function validate() {
 $return = parent::validate();
 if ($return == '') {
 // perform additional validation
 return 'This is a test error'; // note that this is a failure and will trigger the validation error code.
 }
 }
 
 }
 
 $vf = new Myformgeneration('valid');
 ?>
 <style type="text/css">
 <!--
 .validationError {
 border:1px solid red!important;
 }
 
 .validationMessage {
 text-align: center;
 padding: 10px;
 font-size: 130%;
 color: red;
 }
 
 #validationError {
 width: 700px;
 margin: 0 auto;
 }
 
 .required {
 background-color: yellow;
 }
 
 input {
 background-color: #DDFFFF;
 }
 -->
 </style>
 </head>
 <body>
 <?php
 // post submit processing, normally done on thetarget page though one could useredirects
 if (isset($_POST['submit'])) {
 $error = $vf->validate();
 if ($error != '') {
 // do validation error proccessing
 unset ($_POST['submit']); // we don't want this in the post data going back to the original form
 ?>
 <form name="submision_form" id="submision_form" method="POST" action="/">
 <?php echo $vf->savePostGet(); ?>
 <input type="hidden" name="Message" value="<?php echo $error; ?>">
 </form>
 <script type="text/javascript">
 $(document).ready(function() {
 alert ('<?php echo $error; ?>');
 $("#submision_form").submit();
 });
 </script>
 <?php
 exit; // redirect back to the original page
 } else {
 // Save the data or whatever
 }
 }
 ?>
 <h2 style="text-align: center; margin-top: 30px;">Form Generation</h2>
 <?php if (isset($_POST['Message'])) echo '<div class="validationMessage validationError">'.$_POST['Message'].'</div>'; ?>
 <?php echo $vf->open_form()."\n"; ?>
 <table style="margin-top: 10px; margin-left: auto; margin-right: auto;">
 <tr>
 <td valign="top"><?php echo $vf->create_label('name', 'Name')."\n"; ?></td>
 <td>
 <?php echo $vf->create_text('name', 'required')."\n"; ?>
 </td>
 </tr>
 <tr>
 <td valign="top"><?php echo $vf->create_label('comments', 'Comments')."\n"; ?></td>
 <td>
 <?php echo $vf->create_textarea('comments', 'required', 4, 50)."\n"; ?>
 </td>
 </tr>
 <tr>
 <td valign="top"><?php echo $vf->create_label('checkbox1', 'Check Box')."\n"; ?></td>
 <td>
 <?php echo $vf->create_Check('checkbox1')."\n"; ?>
 </td>
 </tr>
 <tr>
 <td valign="top"><?php echo $vf->create_label('dropdownList', 'Dropdown List')."\n"; ?></td>
 <td>
 <?php
 $values = array(
 '' => 'Please Select',
 '1' => 'Option 1',
 '2' => 'Option 2',
 '3' => 'Option 3',
 );
 echo $vf->create_select('dropdownList', 'required', $values)."\n";
 ?>
 </select>
 </td>
 </tr>
 <tr>
 <td valign="top"><?php echo $vf->create_label('group', 'Foods List')."\n"; ?></td>
 <td>
 <?php
 $values = array(
 'Milk' => 'Milk',
 'Butter' => 'Butter',
 'Cheese' => 'Cheese',
 );
 echo $vf->create_radio_group('group', 'required', $values)."\n";
 ?>
 </td>
 </tr>
 <tr>
 <td colspan="2"><center><input type="submit" name="submit" id="submit" value="Submit"></center></td>
 </tr>
 </table>
 <?php echo $vf->close_form()."\n"; ?>
 </body>
 </html>
 |