Thursday, September 18, 2008

Re: Form data from a view element

Hi Luenyar,

I changed the form create line to:

<?php echo $form->create('Comment', array('action' => 'add', 'url' =>
array('controller' => 'comments', 'action' => 'add'))); ?>

And when I submit the element form it _does_ send me to the right
url, that is /comments/add which is the right controller, but it still
says "0 query took ms" and doesn't spew any of the debugging info that
I put in the add() function of the Comments controller.

I'm beginning to think the problem is handing the data off to the
controller. With the debug for cake set in core.php to FULL debug
(i.e. with controller info). I get NO controller information spewed.

Any more ideas? II've been working at this since before the
original post with no progress to a solution :(

- Dan

On Sep 17, 10:12 pm, Luenyar <luen...@gmail.com> wrote:
> $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 <mccarney.dan...@gmail.com> 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 <mark.st...@gmail.com> wrote:
>
> > > On Sep 16, 9:11 am, Daniel <mccarney.dan...@gmail.com> 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: &nbsp;<?php echo $form->input('subject', array( 'label' =>
> > > > false )); ?>
> > > >                 </td>
> > > >         </tr>
> > > >         <tr>
> > > >                 <td>&nbsp;</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 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: