Now here's a tricky extension (still determined to avoid AJAX). When my form fails, and validation errors pop up, how could I have the page jump to an anchor link connected to the form? The top section of my page is somewhat large, so I'd like to avoid excessive scrolling with an anchor link.
+ 1,000,000 bonus points to anyone who can figure this out On Mar 16, 5:07 pm, Johnny Ferguson <[email protected]> wrote: > Having the form submit to the index() function worked brilliantly. To > my surprise, this enabled the automagic validation messages! > > All I have to do now is style the messages with CSS, and I have the > trickiest part of my project done. I'll be sure to post a link to the > blog post I plan to write on this topic when it's finished. I found > plenty of blogs describing what to do generally, but I find they > assumed a great deal of familiarity with the framework. Since this is > a bit of an odd case, I'd like to create a comprehensive guide. > > Thanks a bunch, John. > > On Mar 16, 4:32 pm, John Andersen <[email protected]> wrote: > > > > > You are welcome! :) > > > Another idea, which I do sometime use, is to let the index method > > process the contact add request. > > The way I recognise that the contact add form is the one to process, > > is that I name each submit buttons specifically after what they do - > > in the contact add form case, it would be named "doAddContact". > > The name of the submit button can be found as a key in the $this- > > > >params array. > > > Just an idea, enjoy, > > John > > > On Mar 16, 10:27 pm, Johnny Ferguson <[email protected]> wrote: > > > > Ajax is definitely a working solution, but I'm somewhat leary of > > > requiring users to have javascript enabled (call me a purist :P) > > > > An element is definitely a good idea. I'm still wondering if it would > > > be possible to pass data as part of a redirect. I've thought of > > > writing a function to create this functionality, but I'm not sure if > > > it would break the MVC paradigm. Definitely a function I would be > > > interested in knowing about, or seeing in future versions of CakePHP. > > > > Thanks for the suggestion, John. > > > > On Mar 16, 4:21 pm, John Andersen <[email protected]> wrote: > > > > > I would consider the use of an element to hold the contact form. Then > > > > have the contact form presented in both views! > > > > Seehttp://book.cakephp.org/view/97/Elementsforthestoryon > > > > elements :) > > > > > Later you may consider using an AJAX solution. > > > > Enjoy, > > > > John > > > > > On Mar 16, 9:48 pm, Johnny Ferguson <[email protected]> wrote: > > > > > > Hi, > > > > > > I've poured over all the documentation I possibly can, and searched > > > > > the newsgroups, and haven't yet found a solution to my problem. > > > > > > I'm creating a contact form which doesn't use any databases. As the > > > > > controller action never calls save(), I don't get any of the nice > > > > > automatic validation. > > > > > > Here are my files: > > > > > > Contact Model:http://bin.cakephp.org/view/568757600 > > > > > Contacts Controller:http://bin.cakephp.org/view/1939947381 > > > > > /views/contact/index.ctp (main form):http://bin.cakephp.org/view/ > > > > > 526960429 > > > > > /views/contact/add.ctp:http://bin.cakephp.org/view/378503276 > > > > > > The add() method of my ContactsController will take the data from the > > > > > form at index.ctp, and if it all validates, send off an e-mail. The > > > > > else clause near the bottom of the add() method attempts to send the > > > > > user back to the original form if they made any errors, passing the > > > > > array of errors so that they can be displayed near the form fields. > > > > > > It doesn't look as though $this->redirect() can pass data to a view, > > > > > so I'm wondering how I can achieve this. It just seems inefficient to > > > > > reproduce the form on the add.ctp view. If this is the only option, > > > > > I'll have to go ahead with it, but if anyone can offer a more elegant > > > > > solution, I'd be interested to hear of it. > > > > > > Thanks for having a look. If I get this figured out, I'll be sure to > > > > > write an article on my blog so that complete newbies like myself can > > > > > figure this out. To me a contact form with validation is extremely > > > > > basic, and I didn't figure it would be so hard to get this going. I > > > > > have found articles on how to do this, and although the Contact model > > > > > has a validation array, the errors aren't automagically popping up on > > > > > the form, so I need to do it manually somehow. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] 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
