Add Validation Messages

The Solar_Form::addInvalid() method lets you add "validation failed" messages to an element. These will be in addition to the invalidation messages automatically generated when you call Solar_Form::validate().

Note that this method works with messages on elements; if you wish to add messages about the form as a whole, use the Solar_Form::$feedback public property.

Example

<?php
require_once 'Solar.php';
Solar::start('/path/to/config/Solar.config.php');

$form = Solar::factory('Solar_Form');

$elements = array(
    'name' => array (
        'type' => 'text',
        'label' => 'Your name:',
    ),
    'email' => array (
        'type' => 'text',
        'label' => 'Email address:',
    ),
);    

$form->setElements($elements);

// for some reason, we want one message on the 'name' ...
$form->addInvalid('name', 'You really should type in your name.');

// ... and two messages on the 'email'.
$form->addInvalid('email', array(
        'Be sure to type in your email.',
        'And make it a real one, no fakes!'
));
?>

Of course, you can skip all this if you like and add the messages directly as part of the element to begin with:

<?php
$elements = array(
    'name' => array (
        'type'    => 'text',
        'label'   => 'Your name:',
        'invalid' => array(
            'You really should type in your name.',
        ),
    ),
    'email' => array (
        'type'    => 'text',
        'label'   => 'Email address:',
        'invalid' => array(
            'Be sure to type in your email.',
            'And make it a real one, no fakes!',
        ),
    ),
);
?>
 
manual/form_processing/add_feedback.txt · Last modified: 2008/08/25 08:48 (external edit)