In controller I have
$model=new Userregistration('register');
if(isset($_POST['Userregistration']))
{
$model->attributes=$_POST['Userregistration'];
if($model->validate())
{
// form inputs are valid, do something here
return;
}
}
$countries = Allcountries::model()->findAll(array('order' => 'country ASC'));
$user = Userregistration::model()->findAll();
$this->render('registration',array('model'=>$model, 'countries'=>$countries, 'user'=>$user));
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'userregistration-registration-form',
'enableAjaxValidation'=>false,
)); foreach($countries as $country) ?>
<div class="frmFields">
<?php echo $form->labelEx($model,'title'); ?>
<?php echo $form->dropDownList($model,'title', $user); ?>
<?php echo $form->error($model,'title'); ?>
</div>
<div class="frmFields">
<?php echo $form->labelEx($model,'nationality'); ?>
<?php echo $form->dropDownList($model,'nationality', $country); ?>
<?php echo $form->error($model,'nationality'); ?>
</div>
I’m getting empty data in the first dropdownlist and getting 2 values in the country dropdown. First value is Zimbabwe, the second is it’s dialing code 127. I just want to get the country field values from the table.
If I use <?php echo $form->dropDownList($model,‘nationality’, $country->country); ?> I get error Invalid argument supplied for foreach(). Undefined variable: country
If I remove foreach and use $countries->country I get error: Trying to get property of non-object
If I use $countries[‘country’] I get error: Undefined index: country