【发布时间】:2014-08-20 13:34:20
【问题描述】:
我一直在尝试做的是将数据从我视图中选定的单选按钮传递到控制器中的 php。然后,我将现有的代币余额添加到选定的金额并将其提交回数据库。
问题是我无法从 html 单选按钮获取值到 php 控制器/操作。 我正在使用最新版本的 php 和 YII 框架。
景色
$this->breadcrumbs = array(
'Tokens' => array('index'),
$model->TokenID =>
'buy',
);
?>
<h1>Buy Tokens
</h1>
<?php
echo 'Your balance is ' .$model->TokenAmount;
?>
<FORM name ="form1" method ="post" action = "">
<Input type = 'Radio' Name ='10tokens' value= '10'
>10
<Input type = 'Radio' Name ='25tokens' value= '25'
>25
<Input type = "Submit" Name = "Submit1" VALUE = "Purchase Tokens">
</FORM>
和控制器中的动作
public function actionBuy() {
$_id = Yii::app()->user->getId();
$model = Tokens::model()->findByAttributes(array('UserID' => $_id));
if ($model === null)
throw new CHttpException(404, "Keep calm! If you havent bought tokens before this is normal");
$this->render('buy', array(
'model' => $model,));
// $qty = $_POST['form1'];
// $newtkamount = ($_model->TokenAmount + $qty);
// echo $qty . $newtkamount . $_model->TokenAmount;
}
【问题讨论】:
-
你的 HTML 代码太可怕了。 Please fix the validation errors before you ask a question
-
即不要在标签和属性名称中使用大写字母,尽量将标签放在一行中,不要在标签中使用空的新行...
-
我已经整理好了,html 将在稍后阶段正确完成这只是为了展示它与后端的东西一起工作
标签: php html forms yii controller