2
我有一个表单中的下拉选择标签名称很长的列表。我想实现jquery自动完成但我当前的代码不起作用。正确的方式呈现json在html中
public function executeNew($r) {
$this->getResponse()->setContentType('application/json');
$cityId = Doctrine_Core::getTable('City')->getCity();
return $this->renderText(json_encode($cityId));
$this->form = new VotersForm();
if($r->isMethod('post')) {
$this->errors = array();
$this->form->bind($r->getParameter('voters'));
if($this->form->isValid()) {
$values = $this->form->getValues();
$firstname = $values['firstname'];
$middlename = $values['middlename'];
$lastname = $values['lastname'];
$birthday = $values['birthday'];
$email = $values['email'];
$address = $values['address'];
// $city = $values('city_id');
$city = $cityId;
$cellphone = $values['mobile_no'];
$telephone = $values['telphone_no'];
$profession = $values['profession_id'];
$status = $values['civil_status'];
$comments = $values['comments'];
Doctrine_Core::getTable('Voters')->AddNewVoters($firstname,$middlename,$lastname,$birthday,$email,$address,$city,$cellphone,$telephone,$profession,$status, $comments,$date= date('Y-m-d, h:i:s'));
$this->getUser()->setFlash("good", "You are added successfully");
$this->redirect('duterte/showtotals');
} else {
$this->errors = 'Oops.Something is missing.Please check for required fields';
}
}
}
的$城市场是在一个相关的模型(市)的许多relationship.Using上面的代码,我可以从相关模型“拉” json的,但我的问题是,我的代码不显示形式properly.Instead,它会显示这样的事情
{"Candon":"Candon","Vigan":"Vigan","Alilem":"Alilem","Banayoyo":"Banayoyo","Bantay":"Bantay","Burgos":"Burgos","Cabugao":"Cabugao","Caoayan":"Caoayan","Cervantes":"Cervantes","Galimuyod":"Galimuyod","Gregorio }
如何正确显示的形式,自动完成下拉列表?
<?php if(isset($errors) && !empty($errors)):?>
<div class="alert alert-warning"><?php echo $errors ?></div>
<?php endif ?>
<div class="page-header">
<h3>Register here</h3>
</div>
<form method="post" class="form-horizontal">
<div class="form-group">
<div class="col-sm-10">
<?php echo $form['firstname']->renderRow(array('class'=>'form-control','placeholder' => 'firstname')) ?>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<?php echo $form['middlename']->renderRow(array('class'=>'form-control','placeholder' => 'middlename')) ?>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<?php echo $form['lastname']->renderRow(array('class'=>'form-control','placeholder' => 'lastname')) ?>
</div>
</div>
<div class="form-group">
<div class="col-sm-2">
<?php echo $form['birthday']->renderRow(array('class'=>'form-control','placeholder' => 'birthday')) ?>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<?php echo $form['address']->renderRow(array('class'=>'form-control','placeholder' => 'address')) ?>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<?php echo $form['city_id']->renderRow(array('class'=>'form-control required city_autocomplete')) ?>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<?php echo $form['profession_id']->renderRow(array('class'=>'form-control')) ?>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<?php echo $form['civil_status']->renderRow(array('class'=>'form-control')) ?>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<?php echo $form['comments']->renderRow(array('class'=>'form-control','placeholder' => 'why Duterte')) ?>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" value="I Will Vote Duterte For President" class="btn btn-primary" />
<input type="button" class="btn btn-danger" onclick="resetFunction()" value="Reset form" />
</div>
</div>