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