auto_fill() public method

You can also use this method to set defaults for the form's elements by setting the method's second argument to TRUE. Notes: - unless overridden, the value of {@link Zebra_Form_Password password} controls will always be "12345678"; - unless overridden, the value of controls having the "email" or "emails" {@link Zebra_Form_Control::set_rule() rule} set will be in the form of random_text@random_text.com; - unless overridden, the value of controls having the "url" {@link Zebra_Form_Control::set_rule() rule} set will be in the form of random_text.com, prefixed or not with "http://", depending on the rule's attributes; - {@link Zebra_Form_File file upload} controls and controls having the "captcha" or "regexp" {@link Zebra_Form_Control::set_rule() rule} set will *not* be autofilled; This method will produce results *only* if the form has not yet been submitted! Also, this method will fill elements with random content *only* if the element does not already has a default value! And finally, this method will produce no results unless at some point the form's {@link validate()} method is called.
public auto_fill ( array $defaults = [], boolean $specifics_only = false ) : void
$defaults array An associative array in the form of $element => $value used for filling out specific fields with specific values instead of random ones. For elements that may have more than one value (checkboxes and selects with the "multiple" attribute set) you may set the value as an array. // auto-fill all fields with random values $form->auto_fill(); // auto-fill all fields with random values // except the one called "email" which should have a custom value $form->auto_fill(array( 'email' => 'some@email.com', )); // auto-fill all fields with random values // except a checkboxes group where we select multiple values // note that we use "my_checkboxes" insteas of "my_checkboxes[]" // (the same goes for "selects" with the "multiple" attribute set) $form->auto_fill(array( 'my_checkboxes' => array('value_1', 'value_2'), )); @param boolean $specifics_only (Optional) If set to TRUE only the fields given in the $defaults argument will be filled with the given values and the other fields will be skipped. Can be used as a handy shortcut for giving default values to elements instead of putting default values in the constructor or using the {@link set_attributes()} method. Default is FALSE. @since 2.8.9 @return void
$specifics_only boolean
return void
コード例 #1
0
<h2>A meeting room reservation form</h2>

<p>All fields will be automatically filled with random values - very useful for when debugging forms. The random values will obey the rules set for each element!</p>

<?php 
// include the Zebra_Form class
require '../Zebra_Form.php';
// instantiate a Zebra_Form object
$form = new Zebra_Form('form');
// auto-fill fields with random values
// very useful for when debugging forms
$form->auto_fill();
// the label for the "name" element
$form->add('label', 'label_name', 'name', 'Your name:');
// add the "name" element
$obj = $form->add('text', 'name');
// set rules
$obj->set_rule(array('required' => array('error', 'Name is required!')));
// "email"
$form->add('label', 'label_email', 'email', 'Your email address:');
$obj = $form->add('text', 'email');
$obj->set_rule(array('required' => array('error', 'Email is required!'), 'email' => array('error', 'Email address seems to be invalid!')));
// "department"
$form->add('label', 'label_department', 'department', 'Department:');
$obj = $form->add('select', 'department', '', array('other' => true));
$obj->add_options(array('Marketing', 'Operations', 'Customer Service', 'Human Resources', 'Sales Department', 'Accounting Department', 'Legal Department'));
$obj->set_rule(array('required' => array('error', 'Department is required!')));
// "room"
$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!')));