0
젠드 양식에 라디오 버튼의 값을받는 방법, 나는 1에 라디오 버튼이이 내 모양이다
parent::__construct($name);
$this->setAttribute('method', 'post');
$this->add(array(
'type' => 'Zend\Form\Element\Radio',
'name' => 'rate_box',
'options' => array(
'label' => 'Please choose your rate',
'value_options' => array(
'1' => ' Very Bad',
'2' => ' Bad',
'3' => ' Fine',
'4' => ' Good',
'5' => ' Very Good',
),
),
'attributes' => array(
'value' => '1' //set checked to '1'
)
));
$this->add(array(
'name' => 'submit',
'type' => 'Submit',
'attributes' => array(
'id' => 'submit',
'class' => 'btn btn-primary',
),
));
이 내 컨트롤러의 관련 부분 (아주 나쁜 매우 좋은) 5
$form = new VoteForm();
$request = $this->getRequest();
if ($request->isPost())
{
$form->setData($request->getPost());
if ($form->isValid())
{
$formdata = $form->getData();
$vote = new Vote();
$data = $vote->getArrayCopy();
$data['user_id'] = $user_id;
$data['voted_user_id'] = $voted_user_id;
$data['ratescore'] = $formdata['rate_box']; //Here I take the value of radion button
$vote->populate($data);
try
{
$this->getEntityManager()->persist($vote);
$this->getEntityManager()->flush();
return $this->redirect()->toRoute('home',array('user_id' => $user_id,
'action' => 'home',
));
}
catch(DBALException $e){
}
}
}
"rate_box"의 값을 검색하고 $ data [ 'ratescore']에 저장할 수없는 이유는 무엇입니까? 감사합니다.