【发布时间】:2014-06-21 04:21:50
【问题描述】:
我正在使用 php 为 Wordpress 制作一个插件,该插件使用 post 方法获取平方英尺和价格,然后将它们相乘并输出值。 php 代码在我的本地主机上执行时很好,但在 wordpress 上执行时它总是给我 0。
我尝试为我的变量赋予唯一的名称,并尝试将操作设置为 ''、实际 url、页码,并使用 php 获取页眉。我在堆栈溢出方面看到了几个类似我的问题,但我发现没有一个建议的解决方案对我有用。任何帮助将不胜感激。
<?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
}
}
?>
【问题讨论】: