...

View Full Version : pre populating a form



KevinG
04-24-2003, 12:37 PM
I have a problem. I have a range of cars displayed on this page - http://www.cardriver.co.uk/cars/bmwrange.htm

I want to make it so that when someone clicks on the 'enquiry icon' they got to a form which is pre populated with the make and model of that car.


this site has an example of what i am looking for -

http://www.regtransfers.co.uk/affiliatesystem/searches/searchresults.asp?sitename=autofarm

click on enquire and you'll see the plate info is pre populated in to the form - that is what i want to do.

tommysphone
04-24-2003, 02:45 PM
is one form for each make of car. Code each form the way you want it to appear.

KevinG
04-24-2003, 06:06 PM
every cars in the uk?

can't do that, too many cars. there must be a more simple solution.

pardicity3
04-24-2003, 06:16 PM
I couldn't get that example to work, but I would assume they are using query strings and some sort of server side language. What I would do is have the link look something like:

<a href="carpage.html?car=bmw&engine=v6">BMW V6</a>

Then, I would use php to extract the variables and put them into the form. I.e.:

<form>
<input type="text" value="<?php echo $_GET["car"] ?>" name="cartype" />
<input type="text" value="<?php echo $_GET["engine"] ?>" name="enginetype" />
</form>

That is the easiest way I can think of, though it would recquire formatting your links to have the query strings in them....

KevinG
12-15-2003, 03:46 PM
tried that and i get horrible errors in and around the form fields.

does anyone have any ideas?

BroChris
12-16-2003, 01:15 PM
I'm fairly new to php, so I'm probably wrong, but I think you're getting errors from that method because it's formatted wrong. Instead of having the php code within the html tags, you should have the html tags within the php code. Like this:


<?php
echo "<form>"
echo "<input type=\"text\" value=\"" ?><php echo $_GET["car"] ?><?php echo "\" name=\"cartype\" />" ?>
echo "<input type=\"text\" value=\"" ?><?php echo $_GET["engine"] ?><?php echo "\" name=\"enginetype\" />"
echo "</form>"
?>

I'm probably way off, but it's worth a shot.

Oakendin
12-16-2003, 06:34 PM
I don't know if you have ASP or PHP. Here's a javascript to grab a querystring and get the values you want from it.

Page with the links:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
</head>

<body>
<a href="form.html?car=bmw&&engine=v6">BMW V6</a><br>
<a href="form.html?car=honda&engine=v4">honda V4</a><br>
<a href="form.html?car=toyota&engine=v8">toyota V8</a><br>


</body>
</html>


Page with the form that grabs the values:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
<script language="JavaScript1.2" type="text/javascript">
function getQueryStringValue(queryStringName) {
var value = "";
var qsName = queryStringName + "=";
var theURL = new String(document.URL);
var startValue = 0;
var endValue = 0;

var remainStr = "";

//check to see if the queryStringName is in the url
if (theURL.indexOf(qsName) > -1) {
startValue = theURL.indexOf(qsName) + qsName.length;
}

remainStr = theURL.substring(startValue);

if(remainStr.indexOf("&") > -1) {
endValue = remainStr.indexOf("&");
} else {
endValue = remainStr.length;
}

if(endValue > 0) {
return remainStr.substring(0,endValue);
} else {
return "";
}
}
</script>
</head>

<body>
<form>
<script language="JavaScript1.2" type="text/javascript">
document.write("<input type=text name=cartype");
document.write(" value=");
document.write(getQueryStringValue("car"));
document.write(">");
document.write("<input type=text name=enginetype");
document.write(" value=");
document.write(getQueryStringValue("engine"));
document.write(">");
</script>
</form>

</body>
</html>


You'll need to insert your own query names to "getQueryStringValue("engine")" such as changing it to "getQueryStringValue("color")" if you decide to pass a color via the querystring

Hope this helps.

Paul Jr
12-17-2003, 05:30 AM
Originally posted by pardicity3
<form>
<input type="text" value="<?php echo $_GET["car"] ?>" name="cartype" />
<input type="text" value="<?php echo $_GET["engine"] ?>" name="enginetype" />
</form>


It also might be the double quotes inside the double quotes...

KevinG
01-21-2004, 05:46 PM
still no joy :(

this is the page where people where people can click on a enquiry button next each car -

http://www.cardriver.co.uk/personal%20contract%20cars%201.htm

they are then directed to enquiry page -

http://www.cardriver.co.uk/enquiry2.htm


I am trying to find a way to make it so the first few fields of the enquiry form are prepopulated automacticlly with the users cars details.

I have tried all of the above.

this is the source code of my form. If anyone could help i would be very grateful.

<form method="post" action="thanks.php" name="Lease Enquiry">
<table width="100%" border="0" cellspacing="10" cellpadding="0">
<tr>
<td colspan="2" class="whitetext" height="15" bgcolor="#000000">
<input type="hidden" name="CAR" value="LEAD">
Vehicle Details </td>
</tr>
<tr>
<td width="42%" class="blackbold">Make of
Vehicle<font color="#FF0000"> *</font></td>
<td width="58%"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">
<input type="text" name="Make_of_Vehicle" size="28" maxlength="32" class="boxes">
</font> </td>
</tr>
<tr>
<td width="42%" class="blackbold">Model of
Vehicle <font color="#FF0000"> *</font></td>
<td width="58%"> <span class="smallblack"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">
<input type="text" name="Model_of_Vehicle" size="28" maxlength="32" class="boxes">
</font>(i.e. BMW, 325ci)</span></td>
</tr>
<tr>
<td height="15" class="blackbold">Are you
a business or personal user</td>
<td height="15" class="whitetext"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">
<select name="UserType" class="boxes">
<option selected>Personal User</option>
<option>Business User</option>
<option>Not Sure</option>
</select>
</font> </td>
</tr>
<tr>
<td height="15" class="whitetext"><span class="blackbold">Do
you require any specific optional extras</span><span class="smallblack">
i.e.- sat nav, air con, s/roof, </span></td>
<td height="15" class="whitetext"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">
<textarea name="RequiredExtras" wrap="VIRTUAL" cols="36" rows="4" class="boxes"></textarea>
</font></td>
</tr>
<tr>
<td height="15" class="blackbold">When are
you looking for delivery <font color="#FF0000">*</font></td>
<td height="15" class="whitetext">
<input type="text" name="IdealDeliveryTime" size="28" maxlength="32" class="boxes">
</td>
</tr>
<tr>
<td colspan="2" class="whitetext" height="15" bgcolor="#000000">Finance
Details </td>
</tr>
<tr>
<td width="42%" class="blackbold">Type of
Finance <font color="#FF0000"> *</font></td>
<td width="58%"> <font size="-2" face="Verdana, Arial, Helvetica, sans-serif">
<select name="FinanceType" class="boxes">
<option selected>Hire Purchase</option>
<option>Lease Purchase</option>
<option>Personal Contract Hire</option>
<option>Finance Lease</option>
<option>Personal Contract Purchase</option>
<option>Contract Purchase</option>
<option>Not sure</option>
</select>
</font></td>
</tr>
<tr>
<td width="42%" class="blackbold">How long
would like the Finance <font color="#FF0000">
*</font></td>
<td width="58%"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">
<input type="text" name="TermofFinance" size="28" maxlength="32" class="boxes">
</font></td>
</tr>
<tr>
<td width="42%" class="blackbold">Expected
Annual Mileage <font color="#FF0000"> *</font></td>
<td width="58%"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">
<input type="text" name="AnnualMileage" size="28" maxlength="32" class="boxes">
</font></td>
</tr>
<tr>
<td width="42%" class="blackbold">Would like
a quote with maintenance <font color="#FF0000">
*</font></td>
<td width="58%"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">
<input type="text" name="Maintenance" size="28" maxlength="32" class="boxes">
</font></td>
</tr>
<tr>
<td height="15" class="blackbold">Your Monthly
Payment Budget <font color="#FF0000">*</font></td>
<td height="15" class="whitetext">
<input type="text" name="MonthlyBudget" size="28" maxlength="32" class="boxes">
</td>
</tr>
<tr>
<td colspan="2" height="15" class="whitetext" bgcolor="#000000">Your
Details</td>
</tr>
<tr>
<td width="42%" class="blackbold">Your Full
Name <font color="#FF0000"> *</font></td>
<td width="58%"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">
<input type="text" name="Name" size="28" maxlength="32" class="boxes">
</font></td>
</tr>
<tr>
<td width="42%" class="blackbold">Contact
Telephone Number <font color="#FF0000">
*</font></td>
<td width="58%">
<input type="text" name="Telephone" size="28" maxlength="32" class="boxes">
</td>
</tr>
<tr>
<td width="42%" class="blackbold">Email Address
<font color="#FF0000">*</font> </td>
<td width="58%">
<input type="text" name="Email" size="28" maxlength="32" class="boxes">
</td>
</tr>
<tr>
<td width="42%" class="blackbold"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">Business
Name <span class="smallblack">(if applicable)</span></font></td>
<td width="58%"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">
<input type="text" name="BusinessName" size="28" maxlength="32" class="boxes">
</font></td>
</tr>
<tr>
<td width="42%" class="blackbold"><span class="blackbold">Your
Address and Postcode</span><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><span class="smallblack">
</span></font><font color="#FF0000">*</font><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><span class="smallblack">
<br>
</span></font></td>
<td width="58%">
<textarea name="Address" wrap="VIRTUAL" cols="36" rows="3" class="boxes"></textarea>
</td>
</tr>
<tr valign="middle">
<td colspan="2" class="blackbold" height="20">Please
check this box if you would like a free
insurance quotation on this vehicle
<input type="radio" value="Yes_I_would_an_insurance_Quotation" name="radioButton">
</td>
</tr>
<tr>
<td colspan="2" height="20"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><span class="blackbold">Please
uncheck this box if would not like to join
our monthly newsletter</span>
<input type="radio" value="JoinNewsletterYes" name="radioButton">
</font></td>
</tr>
<tr>
<td height="15" class="whitetext">&nbsp;</td>
<td height="15" class="whitetext"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">
<input type="reset" name="Reset" value=" Reset " class="buttons">
<input type="submit" value="Submit" onClick="MM_validateForm('Make_of_Vehicle','','R','Model_of_Vehicle','','R','IdealDeliveryTime','','R','Annua lMileage','','R','Maintenance','','R','MonthlyBudget','','R','Name','','R','Telephone','','R','Email ','','RisEmail','Address','','R');return document.MM_returnValue" class="buttons" name="submit">
</font></td>
</tr>
<tr>
<td colspan="2" height="15" class="smallblack">&nbsp;</td>
</tr>
</table>
</form>

sweenster
01-26-2004, 12:21 PM
...

sweenster
01-26-2004, 12:21 PM
woah trigger!

right.... first of all - this is just nonsense:



<?php
echo "<form>"
echo "<input type=\"text\" value=\"" ?><php echo $_GET["car"] ?><?php echo "\" name=\"cartype\" />" ?>
echo "<input type=\"text\" value=\"" ?><?php echo $_GET["engine"] ?><?php echo "\" name=\"enginetype\" />"
echo "</form>"
?>


to insert a php variable that has been passed to the script you use <?=$value?> like so:



<form>
<input type="text" name="cartype" value="<?=$cartype?>">
<input type="text" name="engine" value="<?=$engine?>">
</form>


ok secondly... whenever you call the enquiry page up you are referring to: http://www.cardriver.co.uk/enquiry2.htm.

How is enquiry2.htm meant to know the name of the car unless you tell it?!?

instead you should put:


http://www.cardriver.co.uk/enquiry2.htm?car=rover&engine=25
http://www.cardriver.co.uk/enquiry2.htm?car=bmw&engine=315

... and so on... in the hyperlink depending on the type of car.

Now use the script that Oakendin mentioned above and you should be sorted.

holty
01-29-2004, 11:23 AM
If your trying to get results from the querystring, try using get instead of Post

e.g.

<form method="get" action="thanks.php" name="Lease Enquiry">



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum