if (in_array($val, $rules)) { $validation[] = $val; } } } $form = new \Mos\HTMLForm\CForm(array(), array('enter-a-value' => array('type' => 'text'), 'tests' => array('type' => 'checkbox-multiple', 'description' => 'Choose the validation rules to use.', 'values' => $rules), 'submit' => array('type' => 'submit', 'callback' => function ($form) { $form->AddOutput("<p><i>DoSubmit(): Nothing to do.</i></p>"); //$form->AddOutput("<pre>" . print_r($_POST, 1) . "</pre>"); $form->saveInSession = true; return true; }), 'submit-fail' => array('type' => 'submit', 'callback' => function ($form) { $form->AddOutput("<p><i>DoSubmitFail(): Form was submitted but I failed to process/save/validate it</i></p>"); return false; }))); // Set the active validation rules $form->SetValidation('enter-a-value', $validation); // Check the status of the form $status = $form->Check(); // What to do if the form was submitted? if ($status === true) { $form->AddOutput("<p><i>Form was submitted and the callback method returned true.</i></p>"); header("Location: " . $_SERVER['PHP_SELF']); } else { if ($status === false) { $form->AddOutput("<p><i>Form was submitted and the Check() method returned false.</i></p>"); header("Location: " . $_SERVER['PHP_SELF']); } } ?>