$form->create('Comment') associates the form with the 'Comment' model,
but not a controller. Presumably because the 'Comments' model could
be used in many or all of your controllers with $uses. The 'action'
option assumes the current controller, so if you render your element
in the Posts controller, the action is assumed /posts/add. url is the
option you are looking for.
http://manual.cakephp.org/view/183/Creating-Forms#options-url-186
Hope that helps,
Milton
On Sep 16, 11:31 am, Daniel <[EMAIL PROTECTED]> wrote:
> I created the form using the line:
>
> $form->create('Comment', array('action' => 'add'));
>
> Doesn't this specify that it should use the controller associated with
> the "Comment" model, i.e. the Comments controller? This is how I've
> done it with all of my other forms...
>
> And yes, I realize the table based layout is terrible, I'm just
> mocking things at the moment and didn't want to write a stylesheet to
> position things yet.
>
> Thanks!
>
> - Dan
>
> On Sep 16, 11:23 am, mark_story <[EMAIL PROTECTED]> wrote:
>
> > On Sep 16, 9:11 am, Daniel <[EMAIL PROTECTED]> wrote:
>
> > > Hello,
>
> > > I currently have a "comment box" view element that I plan to
> > > embed in various places in my CakePHP application to allow users to
> > > leave comments on various aspects of the site.
>
> > > I'm using the form helper inside of the element to generate the
> > > form to be used to submit the data, however when I submit the data I
> > > receive only a blank screen that says "0 query took ms". I've even
> > > added debugging echoes to the controller to print the data array and
> > > I'm still just receiving a blank page with "0 query took ms".
>
> > > Attached below is the comment "add" method and the respective
> > > element code.
>
> > > Any help anyone can provide would be greatly appreciated, I seem
> > > to be pretty stuck!
>
> > > Controller code:
>
> > > function add()
> > > {
> > > echo "XXXXXXXXXXXXXXXXXXXXXXXX";
> > > $mrClean = new Sanitize();
>
> > > echo "Data ". $this->data;
>
> > > if(!empty($this->data))
> > > {
> > > $mrClean->clean($this->data);
>
> > > $currUser = $this->get_current_user();
> > > $this->data['Comment']['user_id'] = $currUser['id'];
> > > $this->data['Comment']['isDeleted'] = 0;
>
> > > $targetEvent = $this->Event->find("first",
> > > array('conditions' => array('Event.id' =>
> > > $this->data['Comment']
> > > ['event_id']),
> > > 'recursive' => 1));
>
> > > print_r($targetEvent);
>
> > > if(empty($targetEvent) || is_null($targetEvent))
> > > {
> > > $this->Comment->invalidate('event_id', 'You have
> > > selected an
> > > invalid event.');
> > > return;
> > > }
>
> > > if($this->Comment->save($this->data))
> > > {
> > > $this->flash('Your comment has been added',
> > > '/events/view/'.
> > > $this->data['Comment']['event_id']);
> > > } else {
> > > $this->flash('An error has occured adding your
> > > comment.', '/
> > > events');
> > > }
> > > }
>
> > > }
>
> > > Element code:
>
> > > <?php echo $form->create('Comment', array('action' => 'add')); ?>
> > > <table class="commentsTable">
> > > <tr>
> > > <td colspan='99' class='commentSubject'>
> > > Subject: <?php echo $form->input('subject',
> > > array( 'label' =>
> > > false )); ?>
> > > </td>
> > > </tr>
> > > <tr>
> > > <td> </td>
> > > <td class='commentBody'>
> > > <?php echo $form->textarea('body',
> > > array( 'label' => false,
> > > 'rows' => 7,
> > > 'cols' => 80 )); ?>
> > > </td>
> > > </tr>
> > > <tr>
> > > <td colspan='99' class='commentSubmit'>
> > > <?php echo $form->submit('Post Comment'); ?>
> > > </td>
> > > </tr>
> > > </table>
> > > <?php echo $form->hidden('event_id', array('value' => $event_id)); ?>
> > > <?php echo $form->end(); ?>
>
> > Your form doesn't have a controller? how will it know what controller
> > it is supposed to submit to. I would double check that you are being
> > sent to the right URL when submitting the form. Also tables for
> > layout make babies cry :)
>
> > -Mark
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---