Form within a form issue with Paypal buttons - php

I am having an issue with the test PayPal button I created, were it won't fire correctly when placed inside my contact form on my contact.php page. I know that another form cannot exist inside an already created form. I am using PHP to email the form once submitted and I am using "php echo htmlspecialchars($_SERVER["PHP_SELF"])" to provide some sort of feedback once submitted as well. I do not know AJAX and my PHP knowledge is pretty beginner as well. How can I get the PayPal button to still work inside my form and transfer my user to the Paypal payment page while still providing the feedback on site page? This is my code so far:
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]) ?>" method="POST">
<div class="form-group row">
<div class="col-sm-12 col-md-6">
<label for="firstname" class="col-form-label">Name</label>
<input type="text" class="form-control" name="name" id="name" required>
</div>
<div class="col-sm-12 col-md-6">
<label for="firstname" class="col-form-label">Email</label>
<input type="email" class="form-control" name="email" id="email" required>
</div>
</div><!--end form-group row-->
<div class="form-group row">
<div class="col-sm-12 col-md-6">
<label for="phone" class="col-form-label">Phone Number</label>
<input type="text" class="form-control" name="phone" id="phone" required>
</div>
<div class="col-sm-12 col-md-6">
<label for="address" class="col-form-label">Address</label>
<input type="text" class="form-control" name="address" id="address" required>
</div>
</div><!--end-form group row-->
<div class="form-group row">
<div class="col-sm-12 col-md-4">
<label for="city" class="col-form-label">City</label>
<input type="text" class="form-control" name="city" id="city" required>
</div>
<div class="col-sm-12 col-md-4">
<label for="state" class="col-form-label">State</label>
<input type="text" class="form-control" name="state" id="state" required>
</div><div class="col-sm-12 col-md-4">
<label for="zipcode" class="col-form-label">Zipcode</label>
<input type="text" class="form-control" name="zipcode" id="zipcode" required>
</div>
</div><!--end form-group row-->
<div class="row">
<div class="col">
<textarea rows="10" class="form-control" id="groceries" name="groceries" placeholder="LIST SPECIFIC ITEMS (eg: Publix brand gallon of milk or Winn Dixie brand eggs)" required></textarea>
</div>
</div>
<!--Paypal-->
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="5WVQ7ZJD3FDTW">
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
<!--End Paypal-->
<!--<button class="send-btn" type="submit">Order Now!</button> OLD SUBMIT BUTTON-->
</form>

You need to change the tags, since you have to use form in order to utilize the paypal button. You need to use the div tag on the first form tag you used.

Related

How to save data and print form at one click in php?

I am working on invoice where I have to save form's data in database and at the same time it should be print. So, I have 3 pages: invoice.php, invoice_print.php and insert_data.php
invoice_print.php is a html form that should be printed.
Now, user will go to first invoice.php then he will fill details and either he will click on submit button to save data in db or else he will click on print button to print that invoice.
Now, lets come to the second part: If user will select print button then data will go to database first and then it will go to invoice_print.php with same data that he filled.
How to do this? What logic should I use to save data and capture that data's id in button and then send that id on another page to display?
invoice.php:
<form id="demo-form2" action="insert_data.php" method="post" data-parsley-validate class="form-horizontal form-label-left">
<div class="col-md-12 form-group">
<div class="col-md-6">
<label class="control-label">Location</label>
</div>
<div class="col-md-6">
<input class="form-control" type="text" value="" name="designation">
</div>
</div>
<div class="col-md-12 form-group">
<div class="col-md-6">
<label class="control-label">Address</label>
</div>
<div class="col-md-6">
<input class="form-control" type="text" value="" name="contact">
</div>
</div>
</form>
invoice_print.php:
<div class="col-md-12">
<div class="col-md-6">
<h2>DIGILIFE BIZCARE SOLUTIONS</h2>
<p>414, Vashi Infotech Park,Maharashtra</p>
</div>
<div class="col-md-6">
<h2>BILL OF SUPPLY</h2>
</div>
</div>
<div class="col-md-12">
<div class="col-md-6">
<div class="col-md-12">
<div class="col-md-6">
<label>GSTIN</label>
<input type="text" name="gstin" value="">
<label>Serial No & Date of Invoice</label>
<input type="text" name="serialNo">
</div>
<div class="col-md-6">
</div>
</div>
</div>
<div class="col-md-6">
<div class="col-md-12">
<div class="col-md-6">
<label>Mode of Transport</label><br>
<label>Vehicle No</label><br>
<label>Date & Time of Supply</label><br>
<label>Place Of Supply</label>
</div>
<div class="col-md-6s">
<input type="text" name="">
<input type="text" name="">
<input type="text" name="">
<input type="text" name="">
</div>
</div>
</div>
</div>
<div class="col-md-12 form-group">
<div class="col-md-6">
<label class="control-label">Location</label>
</div>
<div class="col-md-6">
<input class="form-control" type="text" value="" name="designation">
</div>
</div>
<div class="col-md-12 form-group">
<div class="col-md-6">
<label class="control-label">Address</label>
</div>
<div class="col-md-6">
<input class="form-control" type="text" value="" name="contact">
</div>
</div>
I would put all of the code for a form into one file, structured thus:
<?php
$formDone=!empty($_POST['formDone']);
$printReq=!empty($_POST['printReq']);
if ($formDone)
{
// perform validation
}
if ($formDone && $validationPassed)
{
// write to database using $_POST data
}
if ($formDone && $databaseWriteSuccess && $printReq)
{
// print using $_POST data
}
// end of PHP
?>
<form method="post" action="<?php echo $PHP_SELF ?>">
<fieldset>
<input type="hidden" name="formDone" value="1" />
</fieldset>
<!-- field forms -->
<input type="submit" value="Save to db" />
<input type="submit" name="printReq" value="Print Invoice" />
</form>

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 to send data to database using form tag?

I can send data to database but using tag. I want to use tag so that the validation in my page will show like "please enter a valid email-address", "password do not match" and many more.
The problem is when I use tag it shows no validation but the data send to db.
But if use tag it shows the validation, but the data is not entering into db.
Here is the view code:
<div class="form-horizontal" id="block-validate">
<?php echo form_open(base_url("index.php/main/editClass"));?>
<div class="form-group">
<label class="control-label col-lg-2"><b>
Course Code-Section
</b></label>
<div class="col-lg-4">
<input class="form-control" name="ccs" type="text" value="<?php echo $Course_Code_Section;?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-2"><b>
Course Description
</b></label>
<div class="col-lg-4">
<input class="form-control" name="des" type="text" value="<?php echo $Description;?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-2"><b>
School Year-Semester
</b></label>
<div class="col-lg-4">
<input class="form-control" name="sys" type="text" value="<?php echo $School_Year_Semester;?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-2"><b>
Room
</b></label>
<div class="col-lg-4">
<input class="form-control" name="rm" type="text" value="<?php echo $Room;?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-2"><b>
Day-Time
</b></label>
<div class="col-lg-4">
<input class="form-control" name="dt" type="text" value="<?php echo $Day_Time;?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-2"><b>
Student
</b></label>
<div class="col-lg-4">
<input class="form-control" name="stu" type="text" value="<?php echo $Student;?>">
</div>
</div>
<div class="form-actions">
<input type="hidden" name="id" value="<?php echo $CID;?>">
<label class="control-label col-lg-2"></label>
<button type="submit" class="btn btn-primary btn-grad btn-rect">Submit</button>
Cancel
</div>
<?php echo form_close();?>
</div>
Here is the code that I am changing:
<div class="form-horizontal" id="block-validate">
And I changed it to:
<form class="form-horizontal" id="block-validate">
When I use the form tag, the url shows this:
http://localhost/ams/index.php/main/showEditClassView?ccs=CPE+506-CPE42FA1&des=Software+Engineering&sys=SY+2016-2017+2nd+Sem&rm=A-225&dt=Saturday-07%3A30+AM-12%3A30+PM&stu=Ronnel+Gonzales&id=1
What if you modify:
<div class="form-horizontal" id="block-validate">
<?php echo form_open(base_url("index.php/main/editClass"));?>
to:
<div class="form-horizontal">
<?php echo form_open(base_url("index.php/main/editClass"), 'id="block-validate"');?>
So that Codeigniter opens the form tag for you, but we use id="block-validate" so your validation can run?
Use method="POST" if you do not want to appear the values in the url.Hope this will sort your problem.
<form class="form-horizontal" id="block-validate" method="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']

Bootstrap HTML form, MySQL query result

I'm in the process of migrating a Drupal build out to Bootstrap framework. In the new Bootstrap framework, I've built out a form to pull results from a database.
Bootstrap form HTML:
<form class="form-horizontal" role="form" method="post" action="<?php echo lookup_dosearchx() ?>">
<br>
<div class="form-group">
<label for="county2" class="col-sm-3 control-label">County:</label>
<div class="col-sm-6">
<input type="text" name="county2" id="county2" class="form-control" placeholder="Enter County Name" required />
</div>
</div>
<hr>
<center><i>Include Payroll Notes:</i></center><br>
<div class="form-group">
<label for="employee" class="col-sm-3 control-label">Employee:</label>
<div class="col-sm-6">
<select class="form-control" name="employee" id="employee" placeholder="Enter Employee Name" /><option>Any</option></select>
</div>
</div>
<div class="form-group">
<label for="startdate" class="col-sm-3 control-label">State Date (mm/dd/yyyy):</label>
<div class="col-sm-6">
<input type="date" name="startdate" id="startdate" class="form-control" placeholder="Enter Start Date" />
</div>
</div>
<div class="form-group">
<label for="enddate" class="col-sm-3 control-label">End Date (mm/dd/yyyy):</label>
<div class="col-sm-6">
<input type="date" name="enddate" id="enddate" class="form-control" placeholder="Enter End Date" />
</div>
</div>
<div class="form-group">
<label for="fulltext" class="col-sm-3 control-label">Fulltext Query:</label>
<div class="col-sm-6">
<textarea class="form-control" name="fulltext" id="fulltext" rows="4" /></textarea>
</div>
</div>
<div class="form-group">
<label for="contain" class="col-sm-3 control-label">Phrase:</label>
<div class="col-sm-6">
<textarea class="form-control" name="contain" id="contain" rows="4" /></textarea>
</div>
</div>
<div class="form-group">
<label for="jobid" class="col-sm-3 control-label">VCS Job Code:</label>
<div class="col-sm-6">
<select class="form-control" name="jobid" id="jobid" placeholder="Enter Job Code" /><option>Any</option></select>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-6">
<button type="submit" class="btn btn-primary">Submit</button>
<button type="reset" class="btn btn-default">Clear</button>
</div>
</div>
</div>
<br>
</form>
I was provided with a large PHP query set from the prior build out, but that code isn't working when I hit submit. The database is connecting fine as I had trouble getting that to work before.
Would it be possible to be pointed in the direction of a simple example or recommended way to build out the PHP query code I'm calling out?

Categories