in my _form. I am recycling or reusing the form but in another controller. Is there any way to address the submitButton to another controller? I am like copy-pasting the actionCreate controller of that form with my new controller except that now it has multiple parameters. Any help please.
What i mean is that they are on the same model since the forms only affect one table in the database. Okay here is my scenario, First I have a form for the user (staff) to allow a customer purchase an item/product. It works well. Now I thought of another option of "what if" the staff will alter the item purchased of the customer?
I cannot use the actionUpdate because in this second form, I have to receive and identify the "type" of the product the staff is altering. I am new to yii and I think I cannot be able to add extra parameters in the actionUpdate controller and implement it in the same form of actionCreate. What I did is that I created a new Controller which is so much alike the actionCreate controller. and a new _form in that case. My problem now is that everytime I clicked the "Create" button in the new form, it marks all the field ERROR (i.e: Price cannot be blank) even if I did put a price in the textfield.
my actionCreate controller:
public function actionCreate($id)
{
$model=new ReleaseItem;
$model->contract_id=$id;
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);
if(isset($_POST['ReleaseItem']))
{
$_POST['ReleaseItem']['tot_price'] = $_POST['ReleaseItem']['price']*$_POST['ReleaseItem']['quantity'];
$model->attributes=$_POST['ReleaseItem'];
if($model->save())
{
$model->updateBalance($id);
$this->redirect(array('servicecontract/view','id'=>$id));
}
}
if (Yii::app()->request->isAjaxRequest) {
Yii::app()->clientScript->scriptMap['jquery.js'] = false;
yii::app()->clientScript->scriptMap['jquery-ui.min.js'] = false;
$this->renderPartial('create',array(
'model'=>$model,'contr_id'=>$id
),false,true);}
}
Good God! This is why I love Yii and the people around it. You guys are so amazing! One thing, the only hindrance I am getting now is that in my separate form, i am including an administrative password in the alteration for security purposes. and with that, I guess the error comes from the save()… since ($model,password) is not in the database table or AR of the model. Am i right? I can’t perform save() correctly. And i want to include the password textfield only in that form (the alteration form). Please. How can i possibly do it. And oh thank you so much for the help!
You can declare an additional attribute in an AR model. It doesn’t need to have a corresponding column in the db table. And you can use “scenario” to specify whether it should be validated or not for a certain situation.