Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 934 Vote(s) - 3.47 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CakePHP extending FormHelper makes errors not report correctly

#1
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!
Reply

#2
As nIcO pointed out to me, this is a great solution, however I was not using my AppFormHelper for the whole form. So this works great, but make sure you use the custom class is used on the whole form.
Reply

#3
*Well, as my comment solved your problem, I take the liberty to write it as an answer... ;-) By the way, I'm happy I could help you !*

To me this seems a quite logical approach.

Not sure if that can be the problem, but did you use your AppFormHelper for the whole form ? I often use a custom helper inheriting from FormHelper myself, and mixing the core helper with mine can bring some problems, for example if you use the SecurityComponent.

Maybe something similar is happening here ?
Reply

#4
To overwrite a HtmlHelper method in Cake 2.0 you can simply:

Create your OwnHelper class containing for example a link method, which extends HtmlHelper, in AppController specify:

$helpers = array('Html' => array('className' => 'OwnHelper'));

via ADmad
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through