Saabana
Saabana

Reputation: 13

pass form entries to another form in different page javascript

I want to pass the value entered by a user in a form field from called fare to a different page has a different form called fare1 in javascript

form1:

<form action="/estimate-fare" name="fare" method="link" enctype="multipart/form-data">   
  <div class="pickupaddressWrapper">
    <label for="pickupaddress">Pickup Address: <span class="form-required" title="This  field is required.">*</span></label>
    <input type="text" maxlength="128" name="pickupaddress" id="pickupaddress" size="30"  value="" class="form-text required" />
  </div>

  <div class="dropoffaddressWrapper">
    <label for="dropoffaddress">Dropoff Address: <span class="form-required" title="This field is required.">*</span></label>
    <input type="text" maxlength="128" name="dropoffaddress" id="dropoffaddress" size="30" value="" class="form-text required" />
  </div>
  <input type="submit"  id="edit-submit" value="" class="form-submit" /> 
</form>

Upvotes: 0

Views: 157

Answers (2)

mtf
mtf

Reputation: 101

After playing around, it hit me... Why not pass the values through another form? No query strings involved, and everything passed right along in the $_POST data.

/estimate-fare/index.php

<?php 
$pickupat = $_POST['pickupaddress'];
$dropoffat = $_POST['dropoffaddress'];
$distance = calcDistance($pickupat,$dropoffat); // the function that calculates or looks up distance between points - (float) miles
$time = calcTime($pickupat,$dropoffat); // function to calculate time taken at present time of day - (int) minutes
$fare1 = $distance * 10 * $distancerate; // meter rate per 10th of a mile
$fare2 = $time * $timerate; // meter rate per minute
$estfare = ($fare1 > $fare2) ? $fare1 : $fare2;
?>
<html>
<body>
 ...
 <form method="post" action="summary.php">
 <input type="text" value="<?php echo $pickupat; ?>">
 <input type="text" value="<?php echo $dropoffat; ?>">
 <input type="text" value="<?php echo $distance; ?> Miles">
 <input type="text" value="<?php echo $time; ?> Minutes">
 <input type="text" value="<?php echo $estfare; ?>">
 <input type="submit" value="Next">
 </form>
 ...
 </body>
 </html>

Upvotes: 1

mtf
mtf

Reputation: 101

If your fare form handler is referring the fare1 page, then one could just pass the value(s) through a query string and suss them out in fare1.

Upvotes: 0

Related Questions