Jonathon Posted February 5, 2013 Share Posted February 5, 2013 Hi, I've read the piece on forms. I am wanting to implement a feedback button that will appear on each page. I'm just thinking as there is no model where is the ideal place for the code for it to go? The SiteController is what i'm thinking, only because it's the default controller. Just wanted some thoughts. Thanks Jonathon Link to comment Share on other sites More sharing options...
Antonio Conte Posted February 5, 2013 Share Posted February 5, 2013 All models can derive from a base model too. If you have repeated code, consider creating a baseModel for this purpose. The default controller does not make sense for validation, but you may utilize the base model there. (using the model's validate method.) Link to comment Share on other sites More sharing options...
Jonathon Posted February 6, 2013 Author Share Posted February 6, 2013 I don't really follow Thomas, sorry. If I can explain it, I just have a feedback button that appears on every page. Currently, I decided to link this to a static page (feedback.php). But i'm not sure where I should put handling the submission, validation and sending the feedback to an email address? Link to comment Share on other sites More sharing options...
Antonio Conte Posted February 6, 2013 Share Posted February 6, 2013 Ok. Then you should scratch my regard for a default model. Not sure where I was going with that anyway now that I think about it. The submission and feedback should be handled by a controller, while the validation should be placed in a model using the rules() method. That method should be initialized in the controller action the submission is done to, with a method call to validate(). You should then send the feedback over email considering validation. As you want this on every page, a default controller makes much sense. Guess you should wait for Larry to confirm if you are unsure about my approach. I got to admit I'm not 100% sure about this one. The email could possible be a model to. It makes sense to me, but I'm not really that sure. Link to comment Share on other sites More sharing options...
Jonathon Posted February 6, 2013 Author Share Posted February 6, 2013 I may have confused you Thomas. I have a button on every page (Send Feedback). Currently that button takes me to a static page called feedback.php which is where the form is. Link to comment Share on other sites More sharing options...
Larry Posted February 6, 2013 Share Posted February 6, 2013 I think this is being thought of as more complicated than it is (if I understand it). Although technically your feedback button is part of a form (as all buttons are), it's really just a link. In fact, you should use a link and style it with CSS to make it look like a button. Then what you're talking about for the actual feedback page is the same as the contact page created by yiic. Just edit and use that. Also, never make a static page with a form that has to be handled. A static page should be just that: unchanging, unresponsive display of information, without user input. Link to comment Share on other sites More sharing options...
Jonathon Posted February 6, 2013 Author Share Posted February 6, 2013 Thanks Larry, I did see in your book the piece on ContactForm and thought it must be similar. Yes it looks like a button, I think that part is where I confused people (sorry). Thanks Link to comment Share on other sites More sharing options...
Antonio Conte Posted February 6, 2013 Share Posted February 6, 2013 Yes. I really bodged this one. 1. Create a simple link to the controller action 2. The controller should serve the form 3. That same form should recive the post request from the form 4. The controller should use a model to validate the post data 5. The controller should send the feedback email as appropriate. (As stated, I'm not sure where the email content belongs. Larry may clarify this.) I think I'm back on safe ground now. Sorry for providing some bad suggestions here. Let a poor man rectify himself a little. Link to comment Share on other sites More sharing options...
Jonathon Posted February 6, 2013 Author Share Posted February 6, 2013 It was pretty straight forward to just copy and edit the ContacfForm code. I want to use Bootsrap with my forms though, so I was reading up about that. Some pople suggest extending CForm which I might have a go at. I will have a fare few forms. Link to comment Share on other sites More sharing options...
Recommended Posts