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

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>

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.

Related

Issue with form action | 404 not found

Path to put form code:
public_html/wp-content/plugins/latepoint/lib/views/customers/dashboard.php
code form:
<form action="update_domain.php" method="post">
<div class="form-group mb-3">
<label for="">Old domain</label>
<input type="text" name="olddomain" class="form-control" />
</div>
<div class="form-group mb-3">
<label for="">New domain</label>
<input type="text" name="newdomain" class="form-control" />
</div>
<div class="form-group mb-3">
<label for="">Username</label>
<input type="text" name="username" class="form-control" />
</div>
<div class="form-group mb-3">
<button type="submit" name="Submit" class="btn btn-primary">Save Data</button>
</div>
</form>
Below path to action code:
public_html/wp-content/plugins/latepoint/lib/views/customers/update_domain.php
Now when I click on sumbit and try run form then I get error:
URL: mywebsite.com/customer-dashboard/updatedomain.php
404
Looks like you are lost.
We can’t seem to find the page you’re looking for.

Passing Values from One Form to another redirected Form in PHP

<form class="form-horizontal" enctype="multipart/form-data" method="post" action="store.php">
<div class="form-group">
<label class="col-sm-2 control-label">REGISTRATION DATE</label>
<div class="col-sm-8">
<input type="date" class="form-control1" name="reg_date" id="focusedinput" placeholder="Default Input">
</div>
<div class="col-sm-2">
<p class="help-block">text!</p>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">REGISTRATION No.</label>
<div class="col-sm-8">
<input type="text" class="form-control1" name="reg_no" id="focusedinput" placeholder="Default Input">
</div>
<div class="col-sm-2">
<p class="help-block">text!</p>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-8">
<input type="SUBMIT" value="Next" class="form-control1">
</div>
</div>
</form>
Here, in this code there are more input types, I just skipped those. When I will press submit button this will take me to 'store.php' file where informations will be stored in database. And redirect me to another form and there are also some input type but I need a information like "reg_no" from the previous form in the current form. How can I get this?
NOTE : I am storing the inputs of first form in a database table. Then redirected to other form and the action of this form is another PHP file like 'store2.php' and it is also using to store informations to other table of database.
You could pass the value of reg_no as a
$_SESSION Variable
to the second form and get it there
You said that you are already passing the information from your current form into a database. When rendering your second form, you could grab whatever value you need from your database, and then add a value attribute to your input.
So for example if you have a form that looks like this in your second form:
<input type="text" class="form-control1" name="reg_no" id="focusedinput" placeholder="Default Input">
You can add that class to Pre-Fill the form when the page loads. Lets say you want it to show "12345":
<input type="text" class="form-control1" name="reg_no" id="focusedinput" placeholder="Default Input" value="12345">
I don't know the details of exactly how you are serving your site through PHP, but you could use some kind of string placeholder, or templating engine to put in this attribute.
Maybe this can help you :
this called form.php :
<form class="form-horizontal" enctype="multipart/form-data" method="POST" action="form_p.php">
<div class="form-group">
<label class="col-sm-2 control-label">REGISTRATION DATE</label>
<div class="col-sm-8">
<input type="date" class="form-control1" name="reg_date" id="focusedinput" placeholder="Default Input">
</div>
<div class="col-sm-2">
<p class="help-block">text!</p>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">REGISTRATION No.</label>
<div class="col-sm-8">
<input type="text" class="form-control1" name="reg_no" id="focusedinput" placeholder="Default Input">
</div>
<div class="col-sm-2">
<p class="help-block">text!</p>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-8">
<input name="submit" type="SUBMIT" value="Next" class="form-control1">
</div>
</div>
</form>
this process of form.php, called form_p.php :
<?php
$reg_date = $_POST['reg_date'];
$reg_no = $_POST['reg_no'];
$submit = $_POST['submit'];
if (isset($submit)) {
$url = 'form_next.php?reg_date=' . $reg_date . '&reg_no=' . $reg_no;
header('Location:' . $url);
}
this next form, called form_next.php :
<?php
$reg_date = $_GET['reg_date'];
$reg_no = $_GET['reg_no'];
?>
<form class="form-horizontal" enctype="multipart/form-data" method="POST" action="form_p_next.php">
<div class="form-group">
<label class="col-sm-2 control-label">REGISTRATION DATE AGAIN</label>
<div class="col-sm-8">
<input type="date" class="form-control1" name="reg_date" id="focusedinput" placeholder="Default Input" value="<?php echo $reg_date; ?>">
</div>
<div class="col-sm-2">
<p class="help-block">text!</p>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">REGISTRATION No. AGAIN</label>
<div class="col-sm-8">
<input type="text" class="form-control1" name="reg_no" id="focusedinput" placeholder="Default Input" value="<?php echo $reg_no; ?>">
</div>
<div class="col-sm-2">
<p class="help-block">text!</p>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-8">
<input name="submit" type="SUBMIT" value="Next" class="form-control1">
</div>
</div>
</form>
and this is process of form_next.php, called form_next_p.php
<?php
//define your code
The code work because I passing reg_date and reg_no from form_p.php to form_next.php and I use $_GET to get reg_date and reg_no and print it in input value.
This is help you?

How send data one page to another page after clicking submit button

i Have a one problem want to share with all of you.
I am develop a custom page in WordPress here is the link of the page http://muhammadimran.info/testing/ when i try to click on new document button and try to submit form it give me error. Here is my code for this please tell me how i can give link in WordPress in action
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<form action="home1.php" enctype="multipart/form-data" method="POST">
<div class="form-group">
<label for="name1">Name</label>
<input name="name" class="form-control" type="text" />
</div>
<div class="form-group">
<label for="title">Title</label>
<input name="title" class="form-control" type="text" />
</div>
<div class="form-group">
<label for="Startdate">Start Date</label>
<input id="datepicker" class="form-control" class="datepicker" type="text" name="start" required="" />
</div>
<div class="form-group">
<label for="Enddate">End Date</label>
<input id="datepicker1" class="form-control" class="datepicker" type="text" name="end" required="" />
</div>
<div class="form-group">
<label for="Users">Users</label>
<input type="text" class="form-control" name="users" />
</div>
<div class="form-group">
<label for="Fileupload">File Upload</label>
<input type="file" class="form-control" name="file" class="file" name="file" required="">
</div>
<input type="submit" id="submit" class="btn btn-primary submitbutton" name="submit">
</form>
</div>
</div>
You should follow the beloe steps:
create a Template:
Home1 Template with file name home1.php
create a page and select the recently create template (Home1 Template).
replace the form action
<form action="home1.php" enctype="multipart/form-data" method="POST">
with
<form action="http://siteur/templateur/" enctype="multipart/form-data" method="POST">
in home1.php
print_r($_POST);

How to Fetch Dynamic input field array items value with different name php mysql?

I have a form like below:
<form id="bookForm" method="post" class="form-horizontal">
<div class="form-group">
<label class="col-xs-1 control-label">Book</label>
<div class="col-xs-4">
<input type="text" class="form-control" name="book[0].title" placeholder="Title" />
</div>
<div class="col-xs-4">
<input type="text" class="form-control" name="book[0].isbn" placeholder="ISBN" />
</div>
<div class="col-xs-2">
<input type="text" class="form-control" name="book[0].price" placeholder="Price" />
</div>
<div class="col-xs-1">
<button type="button" class="btn btn-default addButton"><i class="fa fa-plus"></i></button>
</div>
</div>
How to get value of this form in php $_Post because the name of fields are like <br/>name="book[0].title"**<br/>?
and there are many dynamic different name input fields.
If you can use for multiple books then use book[0].title like below,
<label class="col-xs-1 control-label">Book</label>
<div class="col-xs-4">
<input type="text" class="form-control" name="book[0][title]" placeholder="Title" />
</div>
If you want to use same form then change name of all textbox like,
<form id="bookForm" method="post" class="form-horizontal">
<div class="form-group">
<label class="col-xs-1 control-label">Book</label>
<div class="col-xs-4">
<input type="text" class="form-control" name="book[0][title]" placeholder="Title" />
</div>
<div class="col-xs-4">
<input type="text" class="form-control" name="book[0][isbn]." placeholder="ISBN" />
</div>
<div class="col-xs-2">
<input type="text" class="form-control" name="book[0][price]" placeholder="Price" />
</div>
<div class="col-xs-1">
<button type="submit" class="btn btn-default addButton"><i class="fa fa-plus"></i></button>
</div>
</div>
And get value of this form like echo $_POST['book'][0]['title'];
I hope this can help you.
You need to change name attribute,
<div class="col-xs-4">
<input type="text" class="form-control" name="book_title" placeholder="Title" />
</div>
book[0].title, this is not valid name.
You can now get something like this,
$_POST['book_title']

CodeIgniter Login with enter key

have this in my login form :
<div class="middle-box loginscreen animated fadeInDown">
<div>
<div>
<h1 class="logo-name"><?= $this->lang->line('GGG')?></h1>
</div>
<h3><?= $this->lang->line('GGG')?></h3>
<form class="m-t" role="form" action="welcome/check_user" id="check_user" method="POST">
<div id="save_result"></div>
<div class="form-group has-feedback">
<label class="control-label" for="username"><?= $this->lang->line('Username')?><sup class="mandatory">*</sup></label>
<input type="email" class="form-control required email" placeholder="<?= $this->lang->line('Username')?>" name="username" id="username" maxlength="50">
</div>
<div class="form-group has-feedback">
<label class="control-label" for="password"><?= $this->lang->line('Password')?><sup class="mandatory">*</sup></label>
<input type="password" id="btn" class="form-control required" placeholder="<?= $this->lang->line('Password')?>" name="password" id="password">
</div>
<button type="button" onclick="submit_form('#check_user')" class="btn btn-primary block full-width m-b"><?= $this->lang->line('Login')?></button>
need to get enter button to submit and it wont.
Change button type to submit instead of button - browsers would the submit the form on enter
<button type="submit" onclick="submit_form('#check_user')" class="btn btn-primary block full-width m-b"><?= $this->lang->line('Login')?></button>

Categories