Tuesday, September 16, 2008

Form data from a view element

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(); ?>

--~--~---------~--~----~------------~-------~--~----~
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: