$form = Fieldset::forge( 'settings' )
->add_model( Model_Settings::forge() )
->build( Uri::current() );
public static function set_form_fields( $form, $instance = NULL )
{
// Add the csrf token field to the form
$form->form()->add_csrf();
// Create submit button from template workaround
$form->set_config( 'form_template', str_replace( '{submit}', $form->get_config( 'submit_template' ),
$form->get_config( 'form_template' ) ) );
// Create the base fieldset
parent::set_form_fields( $form, $instance );
// Apply valid bootstrap class to inputs & set validation rules to HTML tag rules
foreach ( $form->field() as $field )
{
if ( $field->type == 'text' )
{
$field->set_attribute( 'class', $form->get_config( 'input_class', 'form-control' ) );
foreach ( $field->rules as $rule )
{
if ( $value = (int)reset( $rule[ 1 ] ) )
{
$rule[ 0 ] == 'max_length' and $field->set_attribute( 'maxlength', $value );
$rule[ 0 ] == 'min_length' and $field->set_attribute( 'minlength', $value );
}
}
}
// Workaround for lack of description template.
// Since we don't want <p></p> to be visible on fields without description
trim( $field->description ) != '' and
$field->set_description( '<p class="help-block">' . $field->description . '</p>' );
}
}
<?php
return [
'default' => [
'prep_value' => TRUE,
'auto_id' => TRUE,
'auto_id_prefix' => 'form_',
'form_method' => 'post',
'form_template' => "\n\t\t{open}\n\t\t<table>\n{fields}\n\t\t</table>\n\t\t{close}\n",
'fieldset_template' => "\n\t\t<tr><td colspan=\"2\">{open}<table>\n{fields}</table></td></tr>\n\t\t{close}\n",
'field_template' => "\t\t<tr>\n\t\t\t<td class=\"{error_class}\">{label}{required}</td>\n\t\t\t<td class=\"{error_class}\">{field} <span>{description}</span> {error_msg}</td>\n\t\t</tr>\n",
'multi_field_template' => "\t\t<tr>\n\t\t\t<td class=\"{error_class}\">{group_label}{required}</td>\n\t\t\t<td class=\"{error_class}\">{fields}\n\t\t\t\t{field} {label}<br />\n{fields}<span>{description}</span>\t\t\t{error_msg}\n\t\t\t</td>\n\t\t</tr>\n",
'error_template' => '<span>{error_msg}</span>',
'group_label' => '<span>{label}</span>',
'required_mark' => '*',
'inline_errors' => FALSE,
'error_class' => NULL,
'label_class' => NULL,
// tabular form definitions
'tabular_form_template' => "<table>{fields}</table>\n",
'tabular_field_template' => "{field}",
'tabular_row_template' => "<tr>{fields}</tr>\n",
'tabular_row_field_template' => "\t\t\t<td>{label}{required} {field} {error_msg}</td>\n",
'tabular_delete_label' => "Delete?",
],
'bootstrap3-admin' => [
'form_template' => "\n\t\t{open}\n\t\t<div class=\"box-body\">\n{fields}</div>\n\t\t<div class=\"box-footer\">{submit}</div>\n\t\t{close}\n",
'form_attributes' => ['class' => 'form-horizontal'],
'field_template' => "\t\t<div class=\"form-group {error_class}\">\n\t\t\t<div class=\"col-sm-3 text-right\">{label} {required}</div>\n\t\t\t<div class=\"col-sm-4\">{field}{description} {error_msg}</div>\n\t\t</div>\n",
'description_template' => '\n\t\t<p class="help-block">{description}</p>',
'submit_template' => '<button type="submit" class="btn btn-primary" role="button">' .
__( 'form.save' ) . '</button>',
'error_class' => 'has-error',
'label_class' => 'control-label',
'input_class' => 'form-control',
'inline_errors' => TRUE,
'error_template' => '<span class="help-block">{error_msg}</span>',
'required_mark' => '<span class="field-required">Required</span>',
]
];
It looks like you're new here. If you want to get involved, click one of these buttons!