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 |