Hi all, this is my first post on yii. First of, i think this framework is awesome, but right now i am having a problem submitting a form. I’m trying to convert the advance search in admin view to a submit form. So far i have succeeded in submitting the form but it inserts each field in the form on after the other. For e.g i have 3 fields(reference, description & price), when i submit the form…
the first field (reference) is first inserted, then,(reference and description) and then (reference, desc & price) all in different rows. Please, how do i avoid this?
My code…admin.php
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$.fn.yiiGridView.update('product-grid', {
data: $(this).serialize()
});
return false;
});
");
Yii::app()->clientScript->registerScript('add', "
$('.addnew-button').click(function(){
$('.add-form').toggle();
return false;
});
$('.add-form form').submit(function(){
$.fn.yiiGridView.update('product-grid', {
data: $(this).serialize()
});
return false;
});
");
?>
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button btn')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->
<?php echo " | " .CHtml::link('Add New','#',array('class'=>'addnew-button btn')); ?>
<div class="add-form" style="display:none">
<?php $this->renderPartial('_form',array(
'model'=>$model,
)); ?>
</div><!-- add-form -->
_form.php
<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
'id'=>'product-form',
'enableAjaxValidation'=>false,
'action'=>Yii::app()->createUrl('inventory/product/create'),
'method'=>'post',
)); ?>
<p class="help-block">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<?php echo $form->textFieldRow($model,'reference',array('class'=>'span5','maxlength'=>100)); ?>
<?php echo $form->textAreaRow($model,'description',array('rows'=>6, 'cols'=>50, 'class'=>'span8')); ?>
<?php echo $form->textFieldRow($model,'price',array('class'=>'span5','maxlength'=>53)); ?>
<div class="form-actions">
<?php $this->widget('bootstrap.widgets.TbButton', array(
'buttonType'=>'submit',
'type'=>'primary',
'label'=>$model->isNewRecord ? 'Create' : 'Save',
)); ?>
</div>
<?php $this->endWidget(); ?>
and controller code…
public function actionCreate()
{
$model=new Product;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Product']))
{
$model->attributes=$_POST['Product'];
$model->coy_id = user()->getModel('coy_id');
if($model->save())
user()->setFlash('success',t('cms','You have succesfully added a new product.'));
$this->redirect(array('quickadmin'));
}
$this->render('create',array(
'model'=>$model,
));
}