validate() public method

Only by calling this method will the form's controls update their values. If this method is not called, all the controls will preserve their default values after submission even if these values were altered prior to submission. This method must be called before the {@link render()} method or error messages will not be available. After calling this method, if there are {@link Zebra_Form_File file} controls on the form, you might want to check for the existence of the {@link $file_upload} property to see the details of uploaded files and take actions accordingly. Client-side validation is done on the "onsubmit" event of the form. See {@link clientside_validation()} for more information on client-side validation.
public validate ( ) : boolean
return boolean Returns TRUE if every rule was obeyed, FALSE if not.
function page_add_bookmark()
{
    $form = new Zebra_Form('form');
    $form->clientside_validation(array('close_tips' => true, 'on_ready' => false, 'disable_upload_validation' => true, 'scroll_to_error' => false, 'tips_position' => 'right', 'validate_on_the_fly' => true, 'validate_all' => true));
    $form->add('label', 'label_url', 'url', 'URL');
    $url = $form->add('text', 'url', 'http://');
    $url->set_rule(array('required' => array('url_error', 'URL musí být vyplněno.'), 'url' => array(true, 'url_error', 'Pole musí obsahovat platné URL (včetně protokolu).')));
    $form->add('label', 'label_title', 'title', 'Název stránky');
    $title = $form->add('text', 'title', '');
    $title->set_rule(array('required' => array('title_error', 'Název musí být vyplněn.')));
    $form->add('submit', 'submitbtn', 'Přidat');
    if ($form->validate()) {
        $ok = model_add($_POST['url'], $_POST['title'], array());
        if ($ok) {
            flash('info', 'Záložka byla vytvořena');
        } else {
            flash('error', 'Záložku se nepodařilo vytvořit.');
        }
        redirect_to('/');
    }
    // set('form', $form->render('views/add_form.php', true));
    set('form', $form->render('', true));
    set('title', 'Nová záložka');
    return html('add.html.php');
}
Example #2
0
/**
	Sets the formulary and returns the values of the fields
*/
function form()
{
    require_once './forms/Zebra_Form.php';
    // instantiate a Zebra_Form object
    $form = new Zebra_Form('form');
    // "submit"
    $form->add('submit', 'btnBack', 'Volver a generar otra consulta');
    // if the form is valid
    if ($form->validate()) {
        header("Location: sentwittmentForm.php");
        exit;
        // otherwise
    } else {
        // generate output using a custom template
        $form->render('*vertical');
    }
}
Example #3
0
/**
	Sets the formulary and returns the values of the fields
*/
function form()
{
    require_once './forms/Zebra_Form.php';
    // instantiate a Zebra_Form object
    $form = new Zebra_Form('form');
    $form->clientside_validation(true);
    // the label for the "query" element
    $form->add('label', 'label_query', 'query', 'Query');
    // add the "query" element
    $obj =& $form->add('text', 'query', '', array('autocomplete' => 'off'));
    // set rules
    $obj->set_rule(array('required' => array('error', 'Se necesita una query')));
    // "Return Per page"
    $form->add('label', 'label_returnpp', 'returnpp', 'Numero de Tweets');
    $obj =& $form->add('text', 'returnpp', 10, array('autocomplete' => 'off'));
    $obj->set_rule(array('digits' => array('', 'error', 'El valor ha de ser un entero'), 'length' => array(0, 3, 'error', 'El numero es demasiado grande'), 'custom' => array('is_valid_number', 'error', 'El numero de Tweets debe ser menor de 500')));
    // "Result Type"
    $form->add('label', 'label_type', 'type', 'Tipo de resultado:');
    $obj =& $form->add('select', 'type', 'mixed');
    $obj->add_options(array('mixed' => 'Mixto', 'recent' => 'Reciente', 'popular' => 'Popular'), true);
    // "submit"
    $form->add('submit', 'btnsubmit', 'Buscar Tweets');
    // if the form is valid
    if ($form->validate()) {
        $values = array();
        foreach ($_POST as $key => $value) {
            if (strpos($key, 'name_') !== 0 && strpos($key, 'timer_') !== 0 && strpos($key, 'response_') !== 0) {
                $values[$key] = $value;
                // echo $key . " " . $values[$key] . "<br>";
            }
        }
        $_SESSION["values"] = $values;
        header("Location: sentwittment.php");
        exit;
        // otherwise
    } else {
        // generate output using a custom template
        $form->render('*horizontal');
    }
}
$form->add('label', 'label_room', 'room', 'Which room would you like to reserve:');
$obj = $form->add('radios', 'room', array('A' => 'Room A', 'B' => 'Room B', 'C' => 'Room C'));
$obj->set_rule(array('required' => array('error', 'Room selection is required!')));
// "extra"
$form->add('label', 'label_extra', 'extra', 'Extra requirements:');
$obj = $form->add('checkboxes', 'extra[]', array('flipchard' => 'Flipchard and pens', 'plasma' => 'Plasma TV screen', 'beverages' => 'Coffee, tea and mineral water'));
// "date"
$form->add('label', 'label_date', 'date', 'Reservation date');
$date = $form->add('date', 'date');
$date->set_rule(array('required' => array('error', 'Date is required!'), 'date' => array('error', 'Date is invalid!')));
// date format
// don't forget to use $date->get_date() if the form is valid to get the date in YYYY-MM-DD format ready to be used
// in a database or with PHP's strtotime function!
$date->format('M d, Y');
// selectable dates are starting with the current day
$date->direction(1);
$form->add('note', 'note_date', 'date', 'Date format is M d, Y');
// "time"
$form->add('label', 'label_time', 'time', 'Reservation time :');
$form->add('time', 'time', '', array('hours' => array(9, 10, 11, 12, 13, 14, 15, 16, 17), 'minutes' => array(0, 30)));
// "submit"
$form->add('submit', 'btnsubmit', 'Submit');
// if the form is valid
if ($form->validate()) {
    // show results
    show_results();
    // otherwise
} else {
    // generate output using a custom template
    $form->render('includes/custom-templates/reservation.php');
}