php - How to get Double Buttons to "fire" in Bootstrap -
i have bootstrap form double buttons (2) shown below.
- the
submit button
fires , returns processing page (i.e., ['php_self']) - however,
cancel button
nothing
how can both buttons fire , return processing page?
<form class="form-horizontal" method="post"> <fieldset> <legend>my form<</legend> <div class="form-group"> <label class="col-md-4 control-label" for="submit"></label> <div class="col-md-8"> <button id="submit" name="submit" class="btn btn-primary" value="1" type="submit">update profile</button> <button id="cancel" name="cancel" class="btn btn-default" value="0" type="submit">cancel update</button> </div> </div> </fieldset> </form>
appended (per threaded comment @fred): added type="submit"
both buttons did not make work. this answer -- works when add type="submit"
appended: here server-side code has been proof cancel button nothing -- didn't think needed prove why cancel button did not work -- thinking experienced bootstrap developer have know right off bat missing:
<?php //this server-side if( $_post['cancel'] ) { echo 'cancel button pressed'; } elseif( $_post['submit'] ) { echo 'submit button pressed'; } ?>
problem here you're using on same page, html form , php.
the reason why it's failing because need use isset()
both of post arrays.
<?php //this server-side if(isset($_post['cancel'] )) { echo 'cancel button pressed'; } if(isset($_post['submit'] )) { echo 'submit button pressed'; } ?>
error reporting have helped here.
- use
type="submit"
buttons.
this answer based on posted html form , php. if javascript used here, type of "firing" mechanism needed.
if want return processing page, can use header redirect or meta refresh or js solution.
consult following on stack on doing redirect:
another option give both buttons same name attribute, , doing:
html
<input type="submit" name="action" value="update profile" /> <input type="submit" name="action" value="cancel update" />
php
if ($_post['action'] == 'update profile') { //action update here } else if ($_post['action'] == 'cancel update') { //action delete } else { //invalid action! }
the above borrowed answer on stack https://stackoverflow.com/a/547848/
you can replace input types buttons , using <button type="submit" ...>
Comments
Post a Comment