php - 2 different action in one form -
i have form called addcustomer.php . it's contain firsname, lastname, mobile fields.i have 2 button on form. onr button saving data , others sending sms customers. want when click second button 3 data fields passed form called smsinfo.php. action saving data works when direct smsinfo . there no data on form .
<form method ="post" name = "custform" action=""> <div class="cell_2_2"><label class="lblfields">firstname:</label> <input type="text" name="firstname" autocomplete="off"/></div> <div class="cell_3_2"><label class="lblfields">lastname :</label> <input type="text" name="lastname" autocomplete="off"/></div> <div class="cell_5_2"><label class="lblfields">mobile :</label> <input type="text" name="mobile" autocomplete="off"/></div> <input type="submit" name="submit" value="save"/> <input type="submit" name="sendsms" value="sms"/> if (isset($_post['submit'])) { saving code here } else if (isset($_post['sendsms'])) { header("location: smsinfo.php"); }
here code of smsinfo.php:
<?php $fname = $_request['firstname']; $lname = $_request['lastname']; $mob = $_request['mobile']; ?> <html> <body> <form action="sendingsms.php" method="post"> <input style="width: 100px;" name="firstname" type="text" value="<?php echo $firstname; ?>"/> <input style="width: 100px;" name="lastname" type="text" value="<?php echo $lastname; ?>"/> <input style="width: 100px;" name="mobile" type="text" value="<?php echo $mobile; ?>"/> </form> </body> </html>
thanks , sorry poor english
approach #1
include smsinfo.php
file instead of redirection:
<?php if ($_server['request_method'] != 'post') { ?> <form method="post" name="custform" action=""> <div class="cell_2_2"> <label class="lblfields">firstname:</label> <input type="text" name="firstname" autocomplete="off" /> </div> <div class="cell_3_2"> <label class="lblfields">lastname :</label> <input type="text" name="lastname" autocomplete="off" /> </div> <div class="cell_5_2"> <label class="lblfields">mobile :</label> <input type="text" name="mobile" autocomplete="off" /> </div> <input type="submit" name="submit" value="save" /> <input type="submit" name="sendsms" value="sms" /> </form> <?php } elseif (isset($_post['submit'])) { //saving code here } elseif (isset($_post['sendsms'])) { include("smsinfo.php"); exit; } ?>
approach #2
add id attribute form , submit buttons elements:
<form method="post" name="custform" id="form-1" action="/" onclick="javascript:return false;"> <div class="cell_2_2"> <label class="lblfields">firstname:</label> <input type="text" name="firstname" autocomplete="off" /> </div> <div class="cell_3_2"> <label class="lblfields">lastname :</label> <input type="text" name="lastname" autocomplete="off" /> </div> <div class="cell_5_2"> <label class="lblfields">mobile :</label> <input type="text" name="mobile" autocomplete="off" /> </div> <input type="submit" name="save" id="button-submit" value="save" /> <input type="submit" name="sendsms" id="button-sms" value="sms" /> </form>
in addition adding javascript codes change action
attribute on clicking button using event listener:
<script type="text/javascript"> document.getelementbyid("button-submit").addeventlistener("click", function() { document.getelementbyid('form-1').action = '/'; document.getelementbyid("form-1").submit(); }); document.getelementbyid("button-sms").addeventlistener("click", function() { document.getelementbyid('form-1').action = '/smsinfo.php'; document.getelementbyid("form-1").submit(); }); </script>
i preferably go second approach.
also note changed submit button name="submit"
attribute name="save"
avoid confliction javascript submit()
method.
Comments
Post a Comment