简体   繁体   中英

echo a function value won't pass on a form

----UPDATE: trying to find a different solution here, please take a look ------- I am trying to post a form with hidden values on a shop platform with payment gateway to receive the values. The value name "Order_Total" uses php echo called "$sum" to display the sum to pay like this:

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

$sum is a function which reads the user order id amount

$order_total    = left_to_pay_for_order($oid);

the function works like this:

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;
}

The Payment gateway receives all other values except the $order_total value.

UPDATE !!! -------------------------------- The value passed as '0' - Any thoughts on that can happen ?

I have tested and the function works prior to sending the form and redirect, the sum display according to expected result on any HTML prior to sending, but the form send value "0".

what am I doing wrong? have searched everywhere. your kind help is very much appreciated.

Thanks !!

As per request here is the whole Form page Code - modified per 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>

Please, tell us what you see in a "inspect".. what the value in the input before post.

But.. with information that you give, I think:

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".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM