【问题标题】:echo a function value won't pass on a form回显函数值不会在表单上传递
【发布时间】:2015-02-28 02:30:31
【问题描述】:

----更新:试图找到不同的解决方案here, please take a look ------- 我正在尝试在带有支付网关的商店平台上发布带有隐藏值的表单以接收值。 值名称 "Order_Total" 使用名为 "$sum" 的 php echo 显示要支付的总和,如下所示:

<Input type="hidden" name="sum" value="<?php echo $order_total; ?>"> 

$sum 是一个读取用户订单id金额的函数

$order_total    = left_to_pay_for_order($oid);

函数是这样工作的:

function left_to_pay_for_order($oid)
{


global $wpdb;
    $s = "select * from ".$wpdb->prefix."order_contents where orderid='$oid' and paid='0'";
    $r = $wpdb->get_results($s);
    $total = 0;
    if(count($r) > 0)
    {
        foreach ($r as $row)
        {
            $total += $row->price * $row->quant;    
            $shp = get_post_meta($row->pid, 'shipping', true)* $row->quant;
            $total += $shp;
        }

    }

return $total;
}

支付网关接收除 $order_total 值之外的所有其他值。

更新!!! -------------------------------- 作为“0”传递的值 - 对此有什么想法吗?

我已经测试并且该功能在发送表单和重定向之前工作,在发送之前根据预期结果在任何 HTML 上显示总和,但表单发送值为“0”。 p>

我做错了什么?到处找。非常感谢您的帮助。

谢谢!!

根据请求,这里是整个表单页面代码 - 根据 StackOverflow 修改:

    <?php

    global $wp_query, $wpdb, $current_user;

    get_currentuserinfo();
    $uid = $current_user->ID;
    $user_email = $current_user->user_email;

    $business = get_option('Theme_tranzilla_ID');
    if(empty($business)) die('ERROR. Please input your tranzilla ID.');
    //-------------------------------------------------------------------------
    $oid = $_GET['oid'];    
    $order_total = Theme_left_to_pay_for_order($oid);
    $title_post = sprintf(__('Order Payment ID #: %s','Walleto'), $oid);


    //---------------------------------


    $tm             = current_time('timestamp',0);
    $cancel_url     = get_bloginfo("siteurl");
    $response_url   = get_bloginfo('siteurl').'/?w_action=tranzila_order_response';
    $ccnt_url       = Theme_my_account_link();
    $currency       = get_option('Theme_currency');

?>


<html>
<head><title>Processing Tranzilla Payment...</title></head>
<body onLoad="document.form_mb.submit();">
<center><h3><?php _e('Please wait, your order is being processed...', 'Theme'); ?></h3></center>

<FORM name="form_mb" Action='https://direct.tranzila.com/Terminal_Name/' method='POST'>
<Input type="hidden" name="supplier" value="<?php echo get_option('Theme_tranzilla_ID') ?>"> 
<Input type="hidden" name="sum" value="<?php echo $order_total; ?>"> 
<Input type="hidden" name="currency" value="1"> 
<input type="hidden" name="email" value="<?php echo $user_email; ?>">

</FORM>




</body>
</html>

【问题讨论】:

  • 我认为你需要使用ajax来得到你想要的
  • PHP 正确打印 HTML 中的值?该行在 HTML 中是什么样的?
  • 调试函数!对函数中的所有变量使用var_dump(),直到发现错误为止。
  • 感谢@JAL!如果我对您的理解正确,则该行是一个动态数值,可以在 HTML 中正确显示。但未通过表单发布。
  • @user2777324 我也觉得是wordpress的问题

标签: php wordpress forms echo payment-gateway


【解决方案1】:

请告诉我们您在“检查”中看到的内容。发布前输入中的值是什么。

但是..根据您提供的信息,我认为:

1) You are missing a ; in the end of "echo $order_total" line. Put a ; in the end.
2) It can be some wordpress conflict with the "sum" field name. Try to change to "order_total".

【讨论】:

  • 感谢您的输入,已修复上面的示例代码。我无法将输入字段名称“sum”更改为其他名称,表单被发送到另一个页面,其中“sum”字段的值应大于 0。您知道 wordpress 中存在这样的冲突吗?谢谢!!
  • 我不太清楚,但有可能...我只是在尝试一些“开箱即用”的方法来帮助您。你能检查那里的 $_POST 吗?总和为空,“”或者它只是不继续发布?
  • 谢谢@Tiago。它是“0”。
猜你喜欢
  • 2016-05-23
  • 1970-01-01
  • 1970-01-01
  • 2021-02-19
  • 1970-01-01
  • 2013-10-22
  • 2021-05-24
  • 2023-03-29
  • 1970-01-01
相关资源
最近更新 更多