Thursday, September 18, 2008

Re: Forms not validating while using EmailComponent?

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" <dec...@gmail.com> 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 cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: