dreamMyDream2014 2014-06-21 04:21
浏览 51
已采纳

Wordpress插件使用php method =“post”不传递值

I am making a plugin for Wordpress using php that uses the post method to get square footage and price, then multiplies them and outputs the value. The php code was fine when executed on my localhost, but it always gives me 0 when executed on wordpress.

I have tried give my variables unique names, and I have tried having the action set to '', the actual url, the page number, and using php to get the page header. I see several questions like mine on stack overflow, but none of the proposed solutions that I found worked for me. Any help would be appreciated.

<?php


//WordPress Hooks 
add_shortcode('jcalc','includeJonnyCalculatorCustom'); 

if (isset($_POST['jcalcthe_squarefeet'])) 
{
    $jcalcthe_squarefeet = $_POST['jcalcthe_squarefeet'];
}
if (isset($_POST['jcalcthe_price']))
{
    $jcalcthe_price = $_POST['jcalcthe_price'];
}

function includeJonnyCalculatorCustom()
{
?>
<p> some text here...
</p>
<?php
if ( isset($_POST['jcalc_calculate']) )
{

$jcalcthe_estimate = ( jcalcthe_squarefeet * jcalcthe_price );
$jcalcthe_estimate = number_format( $jcalcthe_estimate, 2 );
?>
<div>
<form method="post" action=''>

<p> The estimate for your inspection is $
<?php echo $jcalcthe_estimate; ?>
</p>
<button> Back to calculator </button>
</form>
</div>
<?php
}
else
{
?>
<div>
<form method="post" action=''>
<h3> Estimate Calculator </h3>
<label> Square footage of your home: </label>
<input name="jcalcthe_squarefeet" value="<?php echo $jcalcthe_squarefeet ?>"> </input><br /><br />

<label> Price per square foot: </label><br />
<select name="jcalcthe_price" value="<?php echo $jcalcthe_price ?>" style="width: 160px;">
<option value=".15" > $0.15 </option>
<option value=".2" > $0.20 </option>
</select><br /><br />

<button type="submit" style="width: 160px; background-color: lightgrey;"            name="jcalc_calculate"> Calculate estimate </button>

</form>
</div>
<?php
}
}

?>
  • 写回答

1条回答 默认 最新

  • 普通网友 2014-06-21 05:49
    关注

    include your logic in shortcode

    function includeJonnyCalculatorCustom() {
    
        if ( isset($_POST['jcalc_calculate']) ) {
    
    
            if (isset($_POST['jcalcthe_squarefeet'])) {
               $jcalcthe_squarefeet = $_POST['jcalcthe_squarefeet'];
            }
            if (isset($_POST['jcalcthe_price'])) {
               $jcalcthe_price = $_POST['jcalcthe_price'];
           }
    
           $jcalcthe_estimate = ( $jcalcthe_squarefeet * $jcalcthe_price );
           $jcalcthe_estimate = number_format( $jcalcthe_estimate, 2 );
    
           // Rest code here
       }
    
        // Rest Code
        //.........
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图