N. Rosen N. Rosen - 30 days ago 10
PHP Question

php-How to have a button submit and send to page

I'm trying to make a button that submits order input to a database and then takes the user to the home page on my site, but I don't know how to do it. Here is my code:

<button type="submit" class="btn btn-primary" onclick="window.location.href='PurimHome.html'"> Place Order</button>


This button sends the info to the db but it doesn't go to the home page.
Here is more of the code:(I'm using bootstrap)

<form class="form-horizontal" action="" method="post">

<label class="col-sm-2" >Credit Card Number</label>
<div class="col-sm-10">
<input type="number" class="form-control" id="creditnum" name="creditnum" placeholder="Credit Card Number" >
</div>
</div>
<div class="form-group">
<label class="col-sm-2" >Expiration Date</label>
<div class="col-sm-10">
<input type="date" class="form-control" id="date" name="date" placeholder="Expiration Date" >
</div>
</div>
<div class="form-group">
<label class="col-sm-2" >Security Code</label>
<div class="col-sm-10">
<input type="number" class="form-control" id="code" name="code" placeholder="Three Digit Code" >
</div>
</div>
<input type="checkbox" name="contact" id="contact" value="Phone"> Contact Me by Phone<br>

<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary" onclick="window.location.href='PurimHome.html'"> Place Order</button>


</div>
</div>
</form>

Answer Source

If you want to relocate to a different site after you submit.. then maybe you should place in your controller something like..

if(isset($_POST['submit'])){
//do stuff if needed
     header('Location: url');
}

so that after you submit the form it will then redirect you to antoher location of your choosing.