isFieldError takes the full errorString, throws it away and then only
returns true or false; This means that the errors are not avilable to
you to display. strange that this is the case, i'm assuming its some
sort of bug, or something leftover as the code has switched between 2
designs.

I'm not a massively experienced baker, so i did the following.

change cake/libs/views/helpers/form.php

  function generateInputDiv($tagName, $prompt, $required = false,
$errorMsg = null, $size = 20, $htmlOptions = null) {
    $htmlAttributes = $htmlOptions;
    $htmlAttributes['size'] = $size;
    $str = $this->Html->input($tagName, $htmlAttributes);
    $strLabel = $this->labelTag($tagName, $prompt);
    $divClass = "optional";
    if ($required) {
      $divClass = "required";
    }
    $strError = "";


    if ($this->isFieldError( $tagName )) {
      $fieldErrorMessage = $this->getFieldError( $tagName );
      $strError = $this->pTag('error', $fieldErrorMessage);
      $divClass = sprintf("%s error", $divClass);
    }
    $divTagInside = sprintf("%s %s %s", $strError, $strLabel, $str);
    return $this->divTag($divClass, $divTagInside);
  }

see that it now includes a call to getFieldError()

this is a new function that I added which returns the actual error (in
fact, the mostly recently set error for a particular field, as cake
throws others away, afaict)

  function getFieldError( $field ) {
    return $this->Html->tagIsInvalid( $this->Html->model, $this->Html->field );
  }



If a more experienced baker can improve this methodology, please do so.
On 8/3/06, Shutter <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I'm using the Advanced Validation approach by CakeBaker
> (http://wiki.cakephp.org/tutorials:advanced_validation), and trying to
> get errors to display properly if a save() fails. In a nutshell, it
> doesn't display errors because the FormHelper expects
> HtmlHelper::tagIsInvalid() to return 1 if there is an error.
>
> Advanced Validation sets the $validationErrorrs[$model][$field] to a
> _string_ value if I provide an error message.
>
> However, when I use the FormHelper's generateFields() function and it
> generates tags / errors, it requires tagIsInvalid to return the number
> 1:
>
> function isFieldError($field) {
>         $error=1;
>         $this->Html->setFormTag($field);
>
>         if ($error == $this->Html->tagIsInvalid($this->Html->model,
> $this->Html->field)) {
>                 return true;
>         } else {
>                 return false;
>         }
> }
>
> But HtmlHelper::tagIsInvalid() returns the error string I set above,
> not the number one. The documentation says it returns true on errors,
> but it doesn't:
>
> function tagIsInvalid($model, $field) {
>         return empty($this->validationErrors[$model][$field]) ? 0 :
> $this->validationErrors[$model][$field];
>         }
>
> Thus, isFieldError() always returns false, and the FormHelper class
> will refuse to display any error messages.
>
> I could be wrong here, but is there something I'm missing or should
> tagIsInvalid() return 1 instead? I'm still a little foggy on the
> validation stuff, since I need to use Advanced Validation to use
> multiple error messages for the same field. Any insight would be
> helpful.
>
> Thanks,
>
> Shutter
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply via email to