0

WHat I have been trying to do is pass the data from the selected radio button in my view, to the php in the controller. I then add the existing token balance to the selected amount and submit that back into the database.

Problem is I can't get the values from the html radio button to the php controller/action. I am using the latest version of php and YII framework.

The view

$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>

and the action in the controller

  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;
    }
3
  • 1
    Your HTML code is horrendous. Please fix the validation errors before you ask a question Commented Aug 20, 2014 at 13:36
  • 1
    i.e. Don't use uppercase letters in your tag and attribute names, try to keep your tags all on one line, don't use empty new lines inside your tags... Commented Aug 20, 2014 at 13:42
  • I've tidied it up, html will all be done properly at a later stage this is just to show it working with the back end stuff Commented Aug 20, 2014 at 13:46

1 Answer 1

1

You are using different names for the pair of radio buttons. Users will be able to select both radio buttons.

<Input type = 'Radio' Name ='10tokens' value= '10'>10
<Input type = 'Radio' Name ='25tokens' value= '25'>25

You should change both names to the same. Example:

<input type='radio' name='qty' value='10' />10
<input type='radio' name='qty' value='25' />25

Then, you will be able to get the selected radio button value using:

$qty = $_POST['qty'];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.