Populate

Text Fields

If validation fails, these fields would populate using the submitted values:

1
<input name="name" type="text" value="<?php $form->display('name'); ?>">

1
<textarea name="msg"><?php $form->display('msg'); ?></textarea>

More options using display()


Checkboxes and Radio

Convenience method to repopulate checkbox input

1
checked_if( string $field, string $value )

Parameter Type Default Description
$field string null
$value string null
@return string|null

Examples:

1
2
3
<?php // will echo 'checked' if user checked 'green' checkbox

echo $form->checked_if('color', 'green'); // checked

Checkbox:

1
2
3
4
5
6
<input
  name="color[]"
  type="checkbox"
  value="green"
  <?= $form->checked_if('color', 'green'); ?>
>

Radio:

1
2
3
4
5
6
<input
  name="agree"
  type="radio"
  value="yes"
  <?= $form->checked_if('agree', 'yes'); ?>
>


Select and Multi-select

Convenience method to repopulate select input

1
selected_if( string $field, string $value )

Parameter Type Default Description
$field string null
$value string null
@return string|null

Examples:

1
2
3
<?php // will echo 'selected' if user selected 'green' in select input

echo $my_form->selected_if('color', 'green'); // selected

Select:

1
2
3
4
5
6
7
<select name="title">
  <option value="">Select...</option>
  <option value="Mr" <?= $form->selected_if('title', 'Mr'); ?>>Mr</option>
  <option value="Dr" <?= $form->selected_if('title', 'Dr'); ?>>Dr</option>
  <option value="Miss" <?= $form->selected_if('title', 'Miss'); ?>>Miss</option>
  <option value="Mrs" <?= $form->selected_if('title', 'Mrs'); ?>>Mrs</option>
</select>

Multi-select:

1
2
3
4
5
<select name="color[]" multiple>
  <option value="red"<?= $form->selected_if('color', 'red'); ?>>Red</option>
  <option value="blue"<?= $form->selected_if('color', 'blue'); ?>>Blue</option>
  <option value="green"<?= $form->selected_if('color', 'green'); ?>>Green</option>
</select>