08-06-2023, 05:00 PM
I am working on an application using CakePHP (2.x) and I was reusing some settings whenever I was creating a form, so I decided to extend the default FormHelper class that would automatically load the default values if nothing else was passed into it (see code below).
<?php
class AppFormHelper extends FormHelper
{
public function input($fieldName, $options = array())
{
$defaults = array(
'class' => 'input',
'div' => array(
'class' => 'button-height block-label margin-bottom'
)
);
$options = Set::merge($defaults, $options);
return parent::input($fieldName, $options);
}
}
At first glance, this appeared to work perfectly when calling it in my view like this `$this->AppForm->input('test');`. But, when that form is submitted and has an error, that error is not being displayed to the screen. When calling `$this->Form->input('test')` and there is an error, a div is created that looks something like this:
<div class="error-message">This form had an error</div>
Ultimately, I just want to have an easy way to replicate input options for the FormHelper, and thought this was the right way to do it, but since it's creating problems, I am not sure anymore. Anyone know how to make the errors show up again, or have a better solution for providing default options for the FormHelper.
Thanks!
<?php
class AppFormHelper extends FormHelper
{
public function input($fieldName, $options = array())
{
$defaults = array(
'class' => 'input',
'div' => array(
'class' => 'button-height block-label margin-bottom'
)
);
$options = Set::merge($defaults, $options);
return parent::input($fieldName, $options);
}
}
At first glance, this appeared to work perfectly when calling it in my view like this `$this->AppForm->input('test');`. But, when that form is submitted and has an error, that error is not being displayed to the screen. When calling `$this->Form->input('test')` and there is an error, a div is created that looks something like this:
<div class="error-message">This form had an error</div>
Ultimately, I just want to have an easy way to replicate input options for the FormHelper, and thought this was the right way to do it, but since it's creating problems, I am not sure anymore. Anyone know how to make the errors show up again, or have a better solution for providing default options for the FormHelper.
Thanks!