Sort on custom field - sql

I need your help with my widget type code for wordpress. I have a custom field called ordermetakey. I need this below box to sort the posts on this custom field ASC. Its a numeric timestamp.
<div class="list-block">
<ul>
<?php $postslist = get_posts('numberposts=5'); foreach ($postslist as $post) : setup_postdata($post); ?>
<li>
<p><strong><a title="Post: <?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></strong><br \> <span><?php echo get_post_meta($post->ID, 'standplaats', true); ?></span></p>
</li>
<?php endforeach; ?>
</ul>
</div>

<div class="list-block">
<ul>
<?php $postslist = get_posts( array(
'meta_key' => 'ordermetakey',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'posts_per_page' => 5
);
foreach ($postslist as $post) : setup_postdata($post); ?>
<li>
<p><strong><a title="Post: <?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></strong><br \> <span><?php echo get_post_meta($post->ID, 'standplaats', true); ?></span></p>
</li>
<?php endforeach; ?>
</ul>
</div>

Related

how to Get cat id and expertise value in my controler

This is my controller and I am trying to get category id and expertise data from my database field. Everything is working, but the problem is that I'm not getting the category id. The problem occurs when I am trying to print all record on my view controller. here is my part of code $cat_id =Yii::$app->request->get('categori_id');.
//start premium adviser section
public function actionPremiumsearch()
{
if(isset($_GET['login-button1']))
{
$model=new UserDetail();
$request = Yii::$app->request;
$post = $request->get();
$cat_id =Yii::$app->request->get('categori_id');
//var_dump($cat_id);exit;
//print_r($cat_id);exit;
$expertise =Yii::$app->request->get('expertise');
//print_r($expertise);exit;
//var_dump($cat_id);exit;
//$cat = $request->cat_id();
//echo $cat;
//print_r($post);
//$cat_id = $request->get('categori_id');
//echo $cat_id;
//$cat_id = $post['categories']['categori_id'];
//echo $cat_id;exit;
//print_r($cat_id);exit;
//print_r($post);
//$cat_id = $post['categori_id'];
//print_r($cat_id);
//$service_id = $post['Service']['id'];
//echo $service_id.' '.$expertise.' '.$cat_id;
//exit;
//echo "button1";
$query = new Query;
// compose the query
$query->select('kpt_users.*,kpt_user_details.*,kpt_user_services.*')
->from('kpt_users')
->join( 'INNER JOIN',
'kpt_user_details',
'kpt_user_details.user_id =kpt_users.id'
)
->join( 'LEFT JOIN',
'kpt_user_services',
'kpt_user_services.user_id= kpt_users.id'
)
//->Where(['kpt_users.user_role_id' =>$role_id,'kpt_user_services.service_id'=>$service_id])
->Where('kpt_users.status = 1')
->andWhere('kpt_users.user_role_id = 2')
//->andFilterWhere(['like', 'kpt_user_services.service_id', $this->service_id])
//->andFilterWhere(['like', 'kpt_user_details.categori_id', $this->categori_id])
//->andFilterWhere(['like', 'kpt_user_details.expertise', $this->expertise])
//->andWhere(['like', 'kpt_user_services.service_id', $service_id])
//->andWhere(['like', 'kpt_user_details.categori_id', $categori_id])
// ->andWhere(['like', 'kpt_user_details.expertise', $expertise])
//->andWhere('kpt_user_details = 2')
//->andWhere(['like', 'categori_id', $cat_id])
//->andWhere(['like', 'name', 'alex'])
//->andWhere(['like','kpt_user_services.service_id'=>$service_id,'kpt_user_details.categori_id'=>$cat_id])
->limit(2);
// build and execute the query
$rows = $query->all();
//var_dump($rows);exit;
return $this->render('personalinsurance', [
'result' => $rows,
'model' => $model,
]);
}
if(isset($_GET['login-button2'])){
//echo "kanak";
//echo "button1";
$query = new Query;
// compose the query
$query->select('kpt_users.*,kpt_user_details.*,kpt_user_services.*')
->from('kpt_users')
->join( 'INNER JOIN',
'kpt_user_details',
'kpt_user_details.user_id =kpt_users.id'
)
->join( 'LEFT JOIN',
'kpt_user_services',
'kpt_user_services.user_id= kpt_users.id'
)
//->Where(['kpt_users.user_role_id' =>$role_id,'kpt_user_services.service_id'=>$service_id])
->limit(4);
// build and execute the query
$rows = $query->all();
//var_dump($rows);exit;
return $this->render('corporateinsurance', [
'result' => $rows,
]);
}
if(isset($_GET['login-button3'])){
//echo "kanak3";
//echo "button1";
$query = new Query;
// compose the query
$query->select('kpt_users.*,kpt_user_details.*,kpt_user_services.*')
->from('kpt_users')
->join( 'INNER JOIN',
'kpt_user_details',
'kpt_user_details.user_id =kpt_users.id'
)
->join( 'LEFT JOIN',
'kpt_user_services',
'kpt_user_services.user_id= kpt_users.id'
)
//->Where(['kpt_users.user_role_id' =>$role_id,'kpt_user_services.service_id'=>$service_id])
->limit(4);
// build and execute the query
$rows = $query->all();
//var_dump($rows);exit;
return $this->render('sbasedplanning', [
'result' => $rows,
]);
}
if(isset($_GET['login-button4'])){
// echo "kanak4";
//echo "button1";
$query = new Query;
// compose the query
$query->select('kpt_users.*,kpt_user_details.*,kpt_user_services.*')
->from('kpt_users')
->join( 'INNER JOIN',
'kpt_user_details',
'kpt_user_details.user_id =kpt_users.id'
)
->join( 'LEFT JOIN',
'kpt_user_services',
'kpt_user_services.user_id= kpt_users.id'
)
//->Where(['kpt_users.user_role_id' =>$role_id,'kpt_user_services.service_id'=>$service_id])
->Where(['kpt_users.user_role_id' =>$role_id,'kpt_user_details.categori_id'=>$category_id])
->limit(4);
// build and execute the query
$rows = $query->all();
//var_dump($rows);exit;
return $this->render('taxplanning', [
'result' => $rows,
]);
}
}
This is my view controller with the foreach-loop. When I am trying to print the record, the category ID is missing. How can I get all data with category ID?
<?php foreach ($result as $rows):
$path = Yii::$app->params['imagePath'];
// print_r ($rows);exit;
?>
<?php $first_name = $rows['first_name'];
//echo $first_name;exit;
$agency_name = $rows['agency_name'];
$seller_name = $rows['seller_name'];
$reff_no = $rows['reff_no'];
$credentials = $rows['credentials'];
$photo = $rows['photo'];
$contact = $rows['contact'];
//echo $contact;exit;
$year_exp = $rows['year_exp'];
$expertise = $rows['expertise'];
$gender = $rows['gender'];
$title = $rows['title'];
$rnf = $rows['reff_no'];
$user_name = $rows['user_name'];
$user_email = $rows['user_email'];
$first_name = $rows['first_name'];
$user_id = $rows['user_id'];
$user_role_id = $rows['user_role_id'];
$service_id1 = $rows['service_id'];
//print_r( $service_id1);
// $service_name = $rows['service_name'];
$credentials = $rows['credentials'];
//echo "User Name: {$user_name}" . "<br>";
//echo "Ratings: {$rating}" . "<br>";
// echo "RNF: {$reff_no}" . "<br>";
//echo "Service Name: {$title}" . "<br>";
//echo "Service id: {$service_id}" . "<br>";
//echo "user role id: {$user_role_id}" . "<br>";
?>
<div class="parent">
<div class="col-lg-12 no-padding">
<div class="col-lg-6">
<div class="big-image">
<?php if($rows['photo']){ ?>
<img src=<?php echo $path; ?><?php echo $rows['photo']; ?> />
<?php } else { ?>
<?php echo Html::img('#web/images/banner/product-main.png'); ?>
<?php } ?>
<?php //echo Html::img('#web/images/banner/product-main.png'); ?></div>
</div>
<div class="col-lg-6">
<div class="product-name">
<h2><?php //echo $first_name?></h2>
<h2><a target="_blank" href="index.php?r=userslisting/user&id=<?php echo $rows['user_id']; ?>"><?php echo $rows['first_name'];?></a> </h2>
</div>
<div class="rating-point">
<p>Reating 4.5/5</p>
</div>
<div class="star">
<span><?php echo Html::img('#web/images/banner/star-full.png'); ?></span>
<span><?php echo Html::img('#web/images/banner/star-full.png'); ?></span>
<span><?php echo Html::img('#web/images/banner/star-full.png'); ?></span>
<span><?php echo Html::img('#web/images/banner/star-hafe.png'); ?></span>
<span><?php echo Html::img('#web/images/banner/star-0.png'); ?></span>
</div>
<div class="rating-point rnf">
<p class="pro-title">RNF</p>
<p class="pro-head-1"><?php echo $rnf?></p>
</div>
<div class="rating-point rank">
<p class="pro-title">Rank/Title</p>
<p class="pro-head-1"><?php echo $title?></p>
</div>
<div class="rating-point ss">
<p class="pro-title">service specialzation</p>
<p class="pro-head-1"><?php echo $expertise?></p>
</div>
<div class="rating-point creden">
<p class="pro-title">Credentials</p>
<p class="pro-head-1"><?php echo $credentials ?></p>
</div>
<div class="rating-point yoe">
<p class="pro-title">Years OF Experience</p>
<p class="pro-head-1"><?php echo $year_exp ?></p>
</div>
<div class="rating-point mail">
<p class="pro-title">Email</p>
<p class="pro-head-1"><?php echo $user_email; ?></p>
</div>
<div class="view-more">
<input type="button" class="btn btn-primary serch-select view-more" value="ENQUIRE" name="ENQUIRE">
<div class="enquiry">
<?php if (Yii::$app->session->hasFlash('contactFormSubmitted')): ?>
<div class="alert alert-success">
Thank you for contacting us. We will respond to you as soon as possible.
</div>
<?php else: ?>
<form id="contact-form" action="" method="post" role="form">
<div class="form-group">
<div class="col-lg-12 no-padding">
<div class="name-1"><input type="text" name="name" class="form-control transparent" value="" placeholder="Name" required> </div>
<div class="contact-1"><input type="text" name="contact" class="form-control transparent" value="" placeholder="Contact No." required> </div>
</div>
</div>
<div class="form-group">
<div class="col-lg-12 no-padding">
<div class="email-1"><input type="email" name="email" class="form-control transparent" value="" placeholder="Email" required> </div>
<div class="subject-1"><input type="text" name="subject" class="form-control transparent" value="" placeholder="Subject" required></div>
</div>
</div>
<div class="form-group"><textarea name="message" class="form-control" rows="6" placeholder="Message"></textarea></div>
<input id="form-token" type="hidden" name="<?=Yii::$app->request->csrfParam?>"
value="<?=Yii::$app->request->csrfToken?>"/>
<div class="form-group submit-button">
<input type="hidden" name="user_id" value="<?php echo $rows['user_id']; ?>" />
<input type="hidden" name="user_name" value="<?php echo $rows['first_name'].' '.$rows['last_name']; ?>" />
<input type="hidden" name="user_email" value="<?php echo $rows['user_email']; ?>" />
<input type="submit" class="btn btn-primary" name="contact-button">
</div>
</form>
<?php endif; ?>
</div>
</div>
</div>
</div>
<div class="clear"></div>
<?php endforeach; ?>
Here is my form
<div class="serch-select-premium">
<?php $form = ActiveForm::begin(['action' =>['site/premiumsearch'], 'id' => '', 'method' => 'get',]); ?>
<?= $form->field($model, 'type_a_keyword')->textInput(['maxlength' => true, 'placeholder' => "Type a keyword"])->label(false); ?>
<?= Html::submitButton('Personal Insurance', ['class' => '','id' => 'personalinsurance', 'name' => 'login-button1']) ?>
<?= Html::submitButton('Corporate Insurance', ['class' => '','id' => 'corporateinsurance', 'name' => 'login-button2']) ?>
<?= Html::submitButton('Solution Based Planning', ['class' => '', 'id' => 'sbasedplanning','name' => 'login-button3']) ?>
<?= Html::submitButton('Tax Planning', ['class' => '','id' => 'taxplanning', 'name' => 'login-button4']) ?>
<?php ActiveForm::end(); ?>
</div>

use of email format in yii

I am able to send simple email to receiver.Now i have to be able to select a email format from existing different formats and this template must appear in my message box.i should also be able to change the content of the template that appears in message box before sending to receiver.How to do this?
My code for view form
<div class="form wide">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'mail-form',
'enableAjaxValidation'=>true,
'htmlOptions' => array('enctype' => 'multipart/form-data'), // ADD THIS
)); ?>
<div class="row col2">
<?php echo $form->labelEx($model,'email_from'); ?>
<?php echo $form->textField($model,'email_from',array('size'=>50,'maxlength'=>50,'readonly'=>'readonly')); ?>
<?php echo $form->error($model,'email_from'); ?>
</div>
<div class="row col2">
<?php echo $form->labelEx($model,'email_to'); ?>
<?php echo $form->textField($model,'email_to',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($model,'email_to'); ?>
</div>
<div style="clear:both"></div>
<div class="row col2">
<?php echo $form->labelEx($model,'subject'); ?>
<?php echo $form->textField($model,'subject',array('size'=>60,'maxlength'=>250)); ?>
<?php echo $form->error($model,'subject'); ?>
</div>
<div style="clear:both"></div>
<div class="row col2">
<?php echo $form->labelEx($model,'message'); ?>
<?php echo $form->textArea($model,'message',array('style'=>'width: 680px; height: 300px;')); ?>
<?php echo $form->error($model,'message'); ?>
</div>
<div style="clear:both"></div>
<div class="row buttons">
<?php
echo CHtml::submitButton($model->isNewRecord ? 'Send' : 'Send',array('class' => 'btn'));
?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
Try below code:
public function actionContact() {
$model = new ContactForm();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$status = Yii::$app->mailer->compose()
->setTo($model->email_to)
->setFrom([$model->email_from => $model->email_from])
->setSubject($model->subject)
->setTextBody($model->message)
->send();
if ($status) {
Yii::$app->session->setFlash('success', 'Thank you for contacting us. We will respond to you as soon as possible.');
} else {
Yii::$app->session->setFlash('error', 'There was an error sending email.');
}
return $this->refresh();
} else {
return $this->render('contact', [
'model' => $model,
]);
}
}
You can also create a email_template directory under views folder and create template file in which you can set email template content.
you can use js or ajax to do the same.
1: Use jQuery:
I assume that you are using jQuery. So use ajax.
.......JS Cod........
/*I assume that you have your template data in an attribute like data-template-data=""*/
$('#select_template_id').chang(function(){
template=$(this).attr('data-template-data');
$('#template_edit_box').val(template);
});

Issue to open dialog: Yii

I have used ajaxSubmitButton in my form.On click of button i am trying to open dialog When i click the button ,the dialog opens and it displays entire code written for that form . How to resolve this?
my code for button is :
<div class="btnalign" style="margin-top: 20px;margin-left:20px;">
<?=CHtml::ajaxSubmitButton('Mail to Client', Yii::app()->createUrl('reply/composeMail'),
array('type'=>'POST',
'data'=> 'js:{"data1":callData()}',
//'success' => 'function(response){afterSubmitForm(response);}'
'success'=>'js:function(string){ alert(string);$.fn.yiiGridView.update("my-grid"); }'
),
array('class' => 'btn btn-primary'));
?>
</div>
my controller code:
public function actionComposeMail()
{
if(Yii::app()->request->isAjaxRequest){
print_r($_POST['data1']);
if(isset($_POST['data1'])){
$model=new Reply;
$model->scenario = 'compose';
EQuickDlgs::render('_compose',array(
'model'=>$model,
));
}else{
echo "Please select row to Mail.";
}
}
else
{
echo "The request is invalid.";
}
}
my dialog form code is:
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'reply-form',
'enableAjaxValidation'=>true,
'htmlOptions' => array('enctype' => 'multipart/form-data'),
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.For multiple recipients please seperate by comma</p>
<?php echo $form->errorSummary($model); ?>
<div class="row col2">
<?php echo $form->labelEx($model,'email_from'); ?>
<?php echo $form->textField($model,'email_from',array('size'=>50,'maxlength'=>50,'readonly'=>'readonly')); ?>
<?php echo $form->error($model,'email_from'); ?>
</div>
<div class="row col2">
<?php echo $form->labelEx($model,'email_to'); ?>
<?php echo $form->textField($model,'email_to',array('size'=>60,'maxlength'=>150)); ?>
<?php echo $form->error($model,'email_to'); ?>
</div>
<div style="clear:both"></div>
<div class="row col2">
<?php echo $form->labelEx($model,'email_cc'); ?>
<?php echo $form->textField($model,'email_cc',array('size'=>60,'maxlength'=>250)); ?>
<?php echo $form->error($model,'email_cc'); ?>
</div>
<div class="row col2">
<?php echo $form->labelEx($model,'subject'); ?>
<?php echo $form->textField($model,'subject',array('size'=>60,'maxlength'=>250)); ?>
<?php echo $form->error($model,'subject'); ?>
</div>
<div style="clear:both"></div>
<div class="row">
<?php echo $form->labelEx($model,'message'); ?>
<?php echo $form->textArea($model,'message',array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($model,'message'); ?>
</div>
<div style="clear:both"></div>
<div style="clear:both"></div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Send' : 'Send',array('class' => 'btn')); ?>
</div>
<?php $this->endWidget(); ?>
Image of dialog
You must use renderPartial() instead of render() and try to call Yii::app()->end() at the end in your mail form view
public function actionComposeMail()
{
if(Yii::app()->request->isAjaxRequest){
print_r($_POST['data1']);
if(isset($_POST['data1'])){
$model=new Reply;
$model->scenario = 'compose';
$this->renderPartial('_compose',array(
'model'=>$model,
));
}else{
echo "Please select row to Mail.";
}
}
else
{
echo "The request is invalid.";
}
}

Yii CJuiDialog isn't being recognized

I've went through this tutorial http://www.yiiframework.com/wiki/561/ajax-login-form-with-validation-errors-inside-jquery-modal-dialog/ It appears to be functioning properly, but instead of the form being in the modal dialog, it just renders it right on the page like zii.widgets.jui.CJuiDialog isn't even there.
<?php $this->beginWidget('zii.widgets.jui.CJuiDialog',array(
'id'=>'login-dialog',
'options'=>array(
'title'=>'Login',
'autoOpen'=>false,
),
));?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'user_login_form',
'enableAjaxValidation'=>false,
'enableClientValidation'=>true,
'method' => 'POST',
'clientOptions'=>array(
'validateOnSubmit'=>true,
'validateOnChange'=>true,
'validateOnType'=>false,
),
)); ?>
<h1>
Login</h1>
<p>
Please fill out the following form with your login credentials:</p>
<p class="note">
Fields with <span class="required">*</span> are required.</p>
<div id="login-error-div" class="errorMessage" style="display: none;">
</div>
<div class="row">
<?php echo $form->labelEx($model,'username'); ?>
<?php echo $form->textField($model,'username',array("onfocus"=>"$('#login-error- div').hide();")); ?>
<?php //echo $form->error($model,'username'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'password'); ?>
<?php echo $form->passwordField($model,'password',array("onfocus"=>"$('#login-error- div').hide();")); ?>
<?php //echo $form->error($model,'password'); ?>
<p class="hint">
Hint: You may login with <tt>demo/demo</tt>.
</p>
</div>
<div class="row rememberMe">
<?php echo $form->checkBox($model,'rememberMe'); ?>
<?php echo $form->label($model,'rememberMe'); ?>
<?php echo $form->error($model,'rememberMe'); ?>
</div>
<div class="row submit">
<?php echo CHtml::ajaxSubmitButton(
'Sign In',
array('/site/login.GetLogin'),
array(
'beforeSend' => 'function(){
$("#login").attr("disabled",true);
}',
'complete' => 'function(){
$("#user_login_form").each(function(){ this.reset();});
$("#login").attr("disabled",false);
}',
'success'=>'function(data){
var obj = jQuery.parseJSON(data);
// View login errors!
// alert(data);
if(obj.login == "success"){
$("#user_login_form").html("<h4>
Login Successful! Please Wait...</h4>
");
parent.location.href = "/";
}
else{
$("#login-error-div").show();
$("#login-error-div").html("Login failed! Try again.");$("#login-error-div").append("
");
}
}'
),
array("id"=>"login","class" => "btn btn-primary")
); ?>
</div>
<?php $this->endWidget(); ?>
</div>
<!-- form -->
<?php $this->endWidget('zii.widgets.jui.CJuiDialog'); ?>
Its suppose to render like this above so when i click the link below it opens
echo CHtml::link('Login', array('/site/login.GetLogin'), array('onclick'=>'$("#login-dialog").dialog("open"); return false;'));
Its built in a widget, if you have a look at the tutorial. Here's the complete widget
<?php
class loginProvider extends CWidget{
public static function actions(){
return array(
'GetLogin'=>'application.components.actions.getLogin',
);
}
public function run(){
$this->renderContent();
}
protected function renderContent(){
echo '<span style="float:right;">';
if(Yii::app()->user->isGuest){
echo CHtml::link('Login', array('/site/login.GetLogin'), array('onclick'=>'$("#login-dialog").dialog("open"); return false;'));
echo '</span>';
$this->getController()- >renderPartial('application.components.views.login',array('model'=>new LoginForm));
}
else
echo CHtml::link('Logout ('.Yii::app()->user->name.')', array('site/logout'), array('visible'=>!Yii::app()->user->isGuest));
echo '</span>';
}
}

One form and multiple models

I am using Yii Framework.
Purpose: Get user input and insert data into Order and OrderDetail tables on one form. The problem is data is inserted only into the Order table. I have tried to follow the wiki tutorial, but I can't fix this problem.
Why can't I insert data into both tables, Order and OrderDetail?
I have five models:
Customers(customer_id, customer_name, phone, email, lat, lng, ...)
Products(product_id, product_name,price, ...)
Order(order_id,customer_id, order_status, staff_id, ...)
OrderDetail(order_detail_id, order_id,product_id, qty, ...)
Staff(staff_id, staff_name, ...)
OrderController.php
public function actionCreate()
{
$model=new Order;
$orderdetail=new OrderDetail();
$product=new Products();
$date=date('y-m-d');
// Uncomment the following line if AJAX validation is needed
//$this->performAjaxValidation(array($model,$orderdetail));
if(isset($_POST['Order']))
{
$model->attributes=$_POST['Order'];
$model->lat='12.53';
$model->lng='13.2';
$model->completed_date=$date;
$model->received_date=$date;
$model->created_date=$date;
$model->upated_date=$date;
if($model->save())
if(isset($_POST['OrderDetail'])){
$orderdetail->attributes=$_POST['OrderDetail'];
$orderdetail->order_id= $model->order_id;
$orderdetail->order_item_status=1;
$orderdetail->created_date=$date;
$orderdetail->updated_date=$date;
if($orderdetail->save())
$this->redirect(array('view','id'=>$model->order_id));
}
//$OrderDetailController=new OrderDetail();
//$this->redirect(array('OrderDetail/create'));
}
$this->render('create',array(
'model'=>$model,
'orderdetail'=>$orderdetail,
'product'=>$product,
));
}
views/order/create.php
<?php
$this->breadcrumbs=array(
'Orders'=>array('index'),
'Create',
);
$this->menu=array(
array('label'=>'List Order', 'url'=>array('index')),
array('label'=>'Manage Order', 'url'=>array('admin')),
);
?>
<h1>Create Order</h1>
<?php echo $this->renderPartial('_form', array('model'=>$model,'orderdetail'=>$orderdetail,'product'=>$product)); ?>
views/order/_form.php
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'order-form',
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'customer_id'); ?>
<?php //echo $form->textField($model,'customer_id'); ?>
<?php echo $form->dropDownList($model,'customer_id',CHtml::listData(Customers::model()->findAll(),'customer_id','fullname'),
array('empty' => '--- Choose---')); ?>
<?php echo $form->error($model,'customer_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'order_status'); ?>
<?php echo $form->textField($model,'order_status'); ?>
<?php //echo $form->dropDownList($model,'order_id', array(1=>'Pending', 2=>'Processing',3=>'Completed'));?>
<?php echo $form->error($model,'order_status'); ?>
</div>
<?php /*?>
<div class="row">
<?php echo $form->labelEx($model,'lat'); ?>
<?php echo $form->textField($model,'lat'); ?>
<?php echo $form->error($model,'lat'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'lng'); ?>
<?php echo $form->textField($model,'lng'); ?>
<?php echo $form->error($model,'lng'); ?>
</div>
<?php */?>
<div class="row">
<?php echo $form->labelEx($model,'address'); ?>
<?php echo $form->textField($model,'address',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'address'); ?>
</div>
<div class="row">
<?php echo $form->labelEx(Products::model(),'product_id'); ?>
<?php //echo $form->textField($model,'product_id'); ?>
<?php echo $form->dropDownList(Products::model(),'product_id',CHtml::listData(Products::model()->findAll(),'product_id','product_name'),
array('empty' => '--- Choose---')); ?>
<?php echo $form->error(Products::model(),'product_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx(OrderDetail::model(),'qty'); ?>
<?php echo $form->textField(OrderDetail::model(),'qty'); ?>
<?php echo $form->error(OrderDetail::model(),'qty'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'received_date'); ?>
<?php echo $form->textField($model,'received_date'); ?>
<?php echo $form->error($model,'received_date'); ?>
</div>
<?php /*?>
<div class="row">
<?php echo $form->labelEx($model,'completed_date'); ?>
<?php echo $form->textField($model,'completed_date'); ?>
<?php echo $form->error($model,'completed_date'); ?>
</div>
<?php */?>
<div class="row">
<?php echo $form->labelEx($model,'staff_id'); ?>
<?php //echo $form->textField($model,'staff_id'); ?>
<?php echo $form->dropDownList($model,'staff_id',CHtml::listData(Staff::model()->findAll(),'staff_id','fullname'),
array('empty' => '--- Choose---')); ?>
<?php echo $form->error($model,'staff_id'); ?>
</div>
<?php /*?>
<div class="row">
<?php echo $form->labelEx($model,'created_date'); ?>
<?php echo $form->textField($model,'created_date'); ?>
<?php echo $form->error($model,'created_date'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'upated_date'); ?>
<?php echo $form->textField($model,'upated_date'); ?>
<?php echo $form->error($model,'upated_date'); ?>
</div>
<?php */?>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
A form which handles two models... Create a form which has all the attributes for the two models and then in the view when the form is posted and valid save the attributes into two the models.
if(isset($_POST['ModelOneAndModelTwoForm']))
{
$form->attributes=$_POST['ModelOneAndModelTwoForm'];
if($form->validate())
{
$modelOne = new ModelOne();
$modelOne->save();
$modelTwo = new ModelTwo();
$modelTwo->save();
}
}