Pulling one Form Input into Another and Emailing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
landzir101
Forum Newbie
Posts: 3
Joined: Fri Apr 22, 2011 4:43 pm

Pulling one Form Input into Another and Emailing

Post by landzir101 »

I have two forms within the same HTMl sheet (1 for updating a price and the second to actually output everything to an email). The issue I am having is that some key data like Quantity is in the first form and to stop the user from having to put in the same information twice I want to pull the Quantity data bit and put it so that it is outputted in the second form to the email.

The HTML in the first form full pulling the Quantity is:

Code: Select all

<input type="text" value="1" size=1 name="quantity" />
I am able to do something like this (pulling the data from the form above and outputting on the HTML page...but how do I then translate these variables on the separate PHP code gathering the information and emailing?

Code: Select all

<?php 
		$num=$_REQUEST['quantity'];
		$price='10';
		$total = (int)($num * $price);
                echo $num;
		?>
The rest of the variables on the PHP are using the $_POST method. I am not sure if I have to use a $_GET or $_REQUEST on the separate coding.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Pulling one Form Input into Another and Emailing

Post by josh »

You're asking how to do something HTML wasn't designed for. Users don't actually see the form, so why not have 1 big form, use 2 divs to divide them and use CSS to style the divs, this will create the visual appearance of two "input areas" while containing them to one HTML form.
prensil
Forum Newbie
Posts: 15
Joined: Tue Apr 26, 2011 8:38 am
Location: Ahmedabad
Contact:

Re: Pulling one Form Input into Another and Emailing

Post by prensil »

Or try to define some hidden variables and send them in $_GET or $_POST for emailing.
landzir101
Forum Newbie
Posts: 3
Joined: Fri Apr 22, 2011 4:43 pm

Re: Pulling one Form Input into Another and Emailing

Post by landzir101 »

I am not sure if the way I have it set up will allow that (which I then will have to change the way I have it set up). But currently I have it split into two forms because the first form enters a quantity and then the user hits an 'update' button to calculate the total. The form under that then collects all the other data.

First Form (leaving irrelevant parts out):

Code: Select all

 <form method="post" action="">
<input type="text" value="1" size=1 name="quantity" />

<?php
if(isset($_POST['update'])) {
$num = $_POST['quantity'];
$price = '10';
$total = (int)($num * $price);
echo "$".$total.".00";
}
?>

<input type="Submit" name="update" value="update" />
Second Form:

Code: Select all

<form method="post" action="payment_confirmation.php" onSubmit="return ValidateForm()">
<input type="text" name="firstname" />
<input type="text" name="lastname" />
<input type="text" name="email" />
.....
<input type="image" value="Submit" name="imageField" id="imageField" height="46" width="186" src="images/completeorder.png" class="send" />
Do I have to completely change my approach then? Cause obviously the coding conflicts because when I combine it into one form I can either only update the total or submit the form calling the PHP. Appreciate all the help!
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Pulling one Form Input into Another and Emailing

Post by josh »

landzir101 wrote:I am not sure if the way I have it set up will allow that (which I then will have to change the way I have it set up). But currently I have it split into two forms because the first form enters a quantity and then the user hits an 'update' button to calculate the total. The form under that then collects all the other data.
I couldn't think of why that would require 2 forms, in fact it sounds like 1 form is best.
Post Reply