I'm having a zii.widgets.jui.CJuiDialog
box send a form via ajax to my controller. However, when I test the controller for the presence of the post if(isset($_POST['Item']))
. It isn't present and I don't really know why. I'm adapting this post http://www.yiiframework.com/wiki/145/cjuidialog-for-create-new-model/
to fit my own needs.
This is the form within the model:
<div class="form">
<form id="email-item-form" action="/www.mywebsite.ca/item/1/my-first-item" method="post"> <div id="email-item-success" class="label label-success"></div>
<div id="email-item-failure" class="label label-important"></div>
<div class="row">
<label for="Item_email_item">Email this item to:</label> <input placeholder="Send to..." name="Item[email_item]" id="Item_email_item" type="text" /> <div class="errorMessage" id="Item_email_item_em_" style="display:none"></div> </div><!-- row -->
<div class="row">
<label for="Item_email_item_sender">Email sent from:</label>
<input placeholder="Sent from..." name="Item[email_item_sender]" id="Item_email_item_sender" type="text" /> <div class="errorMessage" id="Item_email_item_sender_em_" style="display:none"></div> </div><!-- row -->
<br />
</form>
Controller
public function actionEmail($id)
{
if(isset($_POST['Item']))
{
// Rest of code
}
}
The data is being sent via CHtml::ajax
and declaring 'type'=>'post'
. The process has been working in terms of sending the item id to the controller and sending back responses to the modal box. The problem has started since I tried to confirm the presence of $_POST['Item']
in order to set $model->attributes=$_POST['Item'];
Any help in solving this would be great thank you.
Update to show CHtml::ajax()
var url = '<?php echo Yii::app()->createUrl("item/email", array("id"=>$model->id)); ?>';
<?php echo CHtml::ajax(array(
'url'=>'js:url',
'data'=> "js:$(this).serialize()",
....// Rest of code