自定义表单mysql_自定义表单,计算答案然后更新mysql DB(Custom form, calculate answer then update mysql DB)...

博客讲述了如何在Yii框架下创建一个自定义表单,用于模拟用户购买代币的支付系统。作者遇到的问题是不确定如何在表单中同时展示固定金额选项和滑块选择,并将数据传递到PHP进行处理。讨论中建议使用jQuery来根据用户选择动态禁用/启用相关控件,并在提交时传递所有数据,然后在PHP端过滤处理。
摘要由CSDN通过智能技术生成

自定义表单,计算答案然后更新mysql DB(Custom form, calculate answer then update mysql DB)

我想要实现的是用户购买代币时的模拟支付系统。 我坚持的部分是,创建一个自定义表单,显示3个选项以购买预设数量的令牌包,或者让用户使用滑块。 显然不是两个在同一时间。 我只是不知道如何做到这一点,我第一次尝试使用html表单和html滑块然而我无法将其传递给php,所以我删除了它。

这是我当前的视图和控制器中的方法的代码。 使用yii框架

视图:

/* @var $this TokensController */

/* @var $model Tokens */

$this->breadcrumbs = array(

'Tokens' => array('index'),

$model->TokenID =>

'buy',

);

?>

Buy Tokens

<?php $this->renderPartial('_form', array('model' => $model)); ?>

控制器:

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['tkamount'];

// $newtkamount = ($_model->TokenAmount + $qty);

// echo $qty . $newtkamount;

}

What I'm trying to achieve is a mock payment system for when users purchase tokens. The part I'm stuck on is, creating a custom form displaying 3 options to buy packs of tokens in preset amount, or for the user to use a slider. Obviously not both at the same time. I just have no idea how to do this, my first attempt I did try using html form and html slider however I couldn't get that to pass to the php so I removed it.

Here is my current code for the view and the method in the controller. Using yii framework

View:

/* @var $this TokensController */

/* @var $model Tokens */

$this->breadcrumbs = array(

'Tokens' => array('index'),

$model->TokenID =>

'buy',

);

?>

Buy Tokens

<?php $this->renderPartial('_form', array('model' => $model)); ?>

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['tkamount'];

// $newtkamount = ($_model->TokenAmount + $qty);

// echo $qty . $newtkamount;

}

原文:https://stackoverflow.com/questions/25261929

更新时间:2019-11-06 07:34

最满意答案

我不知道Yii,但我会使用一些JQuery魔法。

制作2个radiobuttons,用户可以选择是否要支付固定金额或使用滑块。 使用JQuery,您现在可以在单击单选按钮时禁用/启用用户想要的控件。 发送数据时,只需发送所有数据,包括radiobutton设置,然后在PHP中过滤掉他不想要的方法,然后就可以了。

I don't know about Yii, but I'd use some JQuery magic.

Make 2 radiobuttons, where user can select if he wants to pay fixed amounts or use a slider. Using JQuery, you now disable/enable the controls the user wants when he clicked the radio buttons. When sending the data, simply send all of it, including the radiobutton setting, and then in the PHP filter out which method he didn't want and there you go.

http://api.jquery.com/change/

2014-08-12

相关问答

这里是你需要的代码, 现在已经美化了 ! = d <?php

include('config.php');

$file = @fopen('country.txt', 'r');

if ($file)

{

while (!feof($file))

{

$line = trim(fgets($file));

$flag = mysql_query($line);

if (isset($flag))

{

...

我不知道Yii,但我会使用一些JQuery魔法。 制作2个radiobuttons,用户可以选择是否要支付固定金额或使用滑块。 使用JQuery,您现在可以在单击单选按钮时禁用/启用用户想要的控件。 发送数据时,只需发送所有数据,包括radiobutton设置,然后在PHP中过滤掉他不想要的方法,然后就可以了。 http://api.jquery.com/change/ < - 用于监视单击radiobuttons的时间 I don't know about Yii, but I'd use so

...

你能试试这个: $vaegtnu=$_POST['vaegtnu'];

$brugerensID= $_SESSION['brugerID'];

mysql_query("UPDATE `brugere` SET vaegtnu='$vaegtnu' WHERE brugerID='$brugerensID'");

告诉我它是否有帮助。 还要检查你的变量是否匹配,即在XXXX = $_POST['YYYY'] YYYY应该是输入的名称,XXXX应该是你在查询中使用的变量的名称。 Can yo

...

...但如果您按提交按钮更新白色电子邮件,它应如下所示: if(isset($_REQUEST['submit'])) {

$fname = mysql_real_escape_string($_POST['forename']);

$sname = mysql_real_escape_string($_POST['surname']);

$emai= mysql_real_escape_string($_POST['email']);

mysql_query(UPDATE `table` SET

...

我在过去做过类似的事情,其中包含一个调度小部件,允许您为日程安排添加日期,就像您有问题的答案一样。 我处理它的方式是通过javascript添加额外的行,增加计数器来命名字段。 像这样的东西:

现在你在javascript中保留一个计数器,你有多少答案,所以当你添加一个新答案时,你只需增加该计数器。 例如,如果您以默认的1个答案开头: va

...

您没有where子句将更新限制为仅编辑的一条记录,例如.. UPDATE albums SET .... WHERE id=$id;

^^^^^^^^^^^^

请记住,sql倾向于“你指定的越少,得到的越多”。 鉴于这种基本错误,我猜你还没有对$name , $artist和$year的数据进行清理和转义,这意味着你的代码容易受到SQL注入攻击 。 You don't have a where clause to restrict the updat

...

你得到哪个成功答案? “成功1”或“成功2” I missed something very simple sorry everyone :( $('#editblog').on('submit', function (e) {

e.preventDefault();

$('input[type=submit]', this).attr('disabled', 'disabled');

var blogTitle = $("#editblogtitle").val();

...

你能尝尝这样的事吗? $database = 'P510F';

$user = 'db2inst1';

$password = 'password';

$hostname = 'localhost';

$port = 50000;

$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;" .

"HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP;UID=$user;PWD=$pa

...

在任何情况下,您都不应该以纯文本格式存储密码。 这意味着当您注册用户时,您应该立即散列密码并在执行insert语句时将其存储为散列格式。 您当前的逻辑以纯文本格式存储密码,如果注册成功,则您尝试更新密码以成为哈希密码。 这意味着如果出现任何问题,您最终可能只在数据库中使用了纯文本密码,无论哪种方式,这意味着在某个特定点上它确实存在于某个给定点的纯文本中不想要。 此外,更新语句除了浪费一些额外的代码行之外没有其他用途。 这样的事应该做: if ( mysqli_num_rows($results)

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值