Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder KevinG's Avatar
    Join Date
    Aug 2002
    Location
    The Matrix
    Posts
    405
    Thanks
    3
    Thanked 0 Times in 0 Posts

    pre populating a form

    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/affili...ename=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.

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    262
    Thanks
    0
    Thanked 0 Times in 0 Posts

    a simple solution

    is one form for each make of car. Code each form the way you want it to appear.
    Therapy is expensive, popping bubble wrap is cheap, you choose.

  • #3
    Regular Coder KevinG's Avatar
    Join Date
    Aug 2002
    Location
    The Matrix
    Posts
    405
    Thanks
    3
    Thanked 0 Times in 0 Posts
    every cars in the uk?

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

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Iowa / Notre Dame
    Posts
    538
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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....
    My Site {Mike's Adventures}

    Yikes, forums are almost too much fun.

  • #5
    Regular Coder KevinG's Avatar
    Join Date
    Aug 2002
    Location
    The Matrix
    Posts
    405
    Thanks
    3
    Thanked 0 Times in 0 Posts
    tried that and i get horrible errors in and around the form fields.

    does anyone have any ideas?

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    Louisville, KY
    Posts
    281
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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:
    Code:
    <?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.

  • #7
    New Coder
    Join Date
    Jul 2002
    Location
    Los Angeles
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:
    Code:
    <!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:
    Code:
    <!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.

  • #8
    Regular Coder
    Join Date
    Dec 2003
    Location
    USA
    Posts
    230
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...

  • #9
    Regular Coder KevinG's Avatar
    Join Date
    Aug 2002
    Location
    The Matrix
    Posts
    405
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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%...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','AnnualMileage','','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>

  • #10
    Regular Coder
    Join Date
    Sep 2002
    Location
    Scotland
    Posts
    407
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ...
    Last edited by sweenster; 01-26-2004 at 12:31 PM.
    My body's a temple... and like those ancient Greek ones it's a ruin
    sweenster.co.uk

  • #11
    Regular Coder
    Join Date
    Sep 2002
    Location
    Scotland
    Posts
    407
    Thanks
    0
    Thanked 0 Times in 0 Posts
    woah trigger!

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

    Code:
    <?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:

    Code:
    <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:
    Code:
    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.
    Last edited by sweenster; 01-26-2004 at 12:31 PM.
    My body's a temple... and like those ancient Greek ones it's a ruin
    sweenster.co.uk

  • #12
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    262
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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">


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •