On 18 Sep 2008, at 23:53, 703designs wrote:

> So a rendered view will automatically receive validation messages? In
> which variable?

Yes. When a model is validated in the controller, invalid fields will  
be noted in a variable. Don't know of the top of my head in which one,  
do a debug($this) in the view and you'll find it. You don't need to  
worry about it though. The FormHelper automatically picks up on this  
variable and prints corresponding error messages. It also picks up on  
data in $this->data to fill in form fields, that's how data is "handed  
back" to the form. The important thing for this to work is that the  
Model.field names are correct, but if it returns to the same form  
(read: renders the same view) the data came from this shouldn't be a  
problem.

You can manually invalidate fields in the controller if you want to  
test this procedure.

> If I need to set a var, what should my target be
> ($this->set('errors', /* what here? */))? I tried substituting a
> minLength 1 rule yesterday and if it worked, I would not have changed
> it, although I can't with certainty say whether validation simply
> never happened or if I got these same errors.
>
> I think that if I render index, that will do the job, as long as I can
> get error messages to present. Isn't there a resource about this
> (practical form validation)? The blog application, if I recall
> correctly, just saves data but doesn't address any fields on an
> individual basis, which I need for my template. I know that I'm
> missing something, and the Model, View, and Controller sections of the
> Cookbook aren't doing much to find the answer (same goes for the
> FormHelper and EmailComponent API docs, the latter of which is
> definitely a work in progress)?
>
> On Sep 18, 10:36 am, "David C. Zentgraf" <[EMAIL PROTECTED]> wrote:
>> I'm not 100% sure, but I think older versions of Cake required you to
>> specify a rule. If you're only interested in the 'required' field,
>> specify a rule that'll always validate, like '/.*/' . What version of
>> Cake are you using?
>>
>> Structure your app the way you see fit. It's not good form to use
>> index() to add data to the database, but that's up to you to decide.
>> Either you make sure that the form submits to the right action (see
>> $form->create() options), or that the action renders the appropriate
>> view when it's done. What works better for you I don't know.
>>
>> On 18 Sep 2008, at 23:18, 703designs wrote:
>>
>>> Right, that was a typo, not a paste. I think that you'll be able to
>>> better help me if you understand how I've designed my contact form:
>>
>>> Model: Contact[name, email, city, subject, message, and a couple
>>> others]
>>> Model['validate']: Name, email, and message have 'required' => true
>>> Views: index (just passes in a pageTitle from the controller and
>>> renders a form from the model using $this->form->create('Contact')  
>>> or
>>> equivalent -- works fine. This form automatically mapped to
>>> ContactsController::add(), so I created that method and put all of  
>>> the
>>> relevant mail logic in there.
>>
>>> So should I move this logic into index() and force the form to use
>>> that method? Or force a render of the index view and find some way  
>>> to
>>> pass in the validation errors?
>>
>>> Thanks for the help!
>>
>>> On Sep 18, 9:29 am, "David C. Zentgraf" <[EMAIL PROTECTED]> wrote:
>>>> On 18 Sep 2008, at 21:50, 703designs wrote:
>>
>>>>> I got funny preg_match errors
>>
>>>> Show us your $validate rules then or go through them with a fine
>>>> comb.
>>
>>>>> $this->Contact->set('$this->data);
>>
>>>> I hope this is not copy&pasted as it's invalid PHP.
>>
>>>>> This controller's 'add' method just sends out emails
>>>>> and flashes a message to the homepage. What do I need to do for  
>>>>> the
>>>>> form to point to this method, but for validation errors to show up
>>>>> on
>>>>> the form (repopulating fields)?
>>
>>>> What view is your form in then? The add action will automatically  
>>>> try
>>>> to render the add view, naturally. If this is not where your form  
>>>> is,
>>>> override it with $this->render();
>>
>>>>> This is not very well-documented, or
>>>>> if it is, I had difficulty finding an answer.
>>
>>>> http://book.cakephp.org/view/428/render
>>
>>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to