Wordpress plugin using php method="post" not passing values -
Wordpress plugin using php method="post" not passing values -
i making plugin wordpress using php uses post method square footage , price, multiplies them , outputs value. php code fine when executed on localhost, gives me 0 when executed on wordpress.
i have tried give variables unique names, , have tried having action set '', actual url, page number, , using php page header. see several questions mine on stack overflow, none of proposed solutions found worked me. help 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> 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> estimate inspection $ <?php echo $jcalcthe_estimate; ?> </p> <button> calculator </button> </form> </div> <?php } else { ?> <div> <form method="post" action=''> <h3> estimate calculator </h3> <label> square footage of home: </label> <input name="jcalcthe_squarefeet" value="<?php echo $jcalcthe_squarefeet ?>"> </input><br /><br /> <label> cost 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 } } ?>
include 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 //.........
php wordpress forms post
Comments
Post a Comment