admin管理员组

文章数量:1291147

I have this Landing Page that I need to pre-populate with form values after it is submitted. Essentially in the end I have to make the url look like this...

.php?sid=xx&pub=xxxxx&c1=&c2=&c3=&append=1&firstname=Test&lastname=Smith&address=2211+Commerce+St.&city=Dallas&state=TX&zipcode=75080&[email protected]

What I currently have now for the form is...

<form name="regForm" method="get" action=".php?sid=xx&pub=xxxx&c1=&c2=&c3=&append=1">
    <input id="firstname" class="text" type="text" name="firstname"/><br>
    <input id="lastname" class="text" type="text" name="lastname" /><br>
    <input id="email" class="text" type="text"  name="email" /><br>
    <input id="address" class="text" type="text" /><br>
    <input id="city" class="text" type="text"/><br>
    <input id="zipcode" class="text" type="text" maxlength="5" name="zipcode" /><br>
    <input type="submit" value="Send Me My FREE List" id="submitBtn2"/>
</form>

How do i create that URL above after the form is submitted? I have been racking my brain all day on this and can't figure it out, i feel like im close.

thanks for the help!

I have this Landing Page that I need to pre-populate with form values after it is submitted. Essentially in the end I have to make the url look like this...

http://example./r.php?sid=xx&pub=xxxxx&c1=&c2=&c3=&append=1&firstname=Test&lastname=Smith&address=2211+Commerce+St.&city=Dallas&state=TX&zipcode=75080&[email protected]

What I currently have now for the form is...

<form name="regForm" method="get" action="http://example./r.php?sid=xx&pub=xxxx&c1=&c2=&c3=&append=1">
    <input id="firstname" class="text" type="text" name="firstname"/><br>
    <input id="lastname" class="text" type="text" name="lastname" /><br>
    <input id="email" class="text" type="text"  name="email" /><br>
    <input id="address" class="text" type="text" /><br>
    <input id="city" class="text" type="text"/><br>
    <input id="zipcode" class="text" type="text" maxlength="5" name="zipcode" /><br>
    <input type="submit" value="Send Me My FREE List" id="submitBtn2"/>
</form>

How do i create that URL above after the form is submitted? I have been racking my brain all day on this and can't figure it out, i feel like im close.

thanks for the help!

Share Improve this question edited Jun 13, 2012 at 22:28 DEM asked Jun 13, 2012 at 22:23 DEMDEM 3332 gold badges4 silver badges16 bronze badges 4
  • 1 x*x.? better use example. – powtac Commented Jun 13, 2012 at 22:25
  • 1 I'm now following. You've got method="get" set, so it should just work as-is. What url do you get when you submit? – Ben Lee Commented Jun 13, 2012 at 22:26
  • Or do you mean you want to fill the values using the value attribute like this? <input id="firstname" class="text" type="text" name="firstname" value="Test"/> – Ben Lee Commented Jun 13, 2012 at 22:27
  • @BenLee i get this "example./r.php?firstname=D&lastname=M&email=dave%40eternalnyc.&state=&zipcode=89078&look=Single+Family+Home " – DEM Commented Jun 13, 2012 at 22:30
Add a ment  | 

3 Answers 3

Reset to default 7

Include the extra parameters as hidden form fields instead of inline query parameters:

<form name="regForm" method="get" action="http://example./r.php">
    <input type="hidden" name="sid" value="xx" />
    <input type="hidden" name="pub" value="xxxx" />
    <input type="hidden" name="c1" value="" />
    <input type="hidden" name="c2" value="" />
    <input type="hidden" name="c3" value="" />
    <input type="hidden" name="append" value="1" />

    <input id="firstname" class="text" type="text" name="firstname"/><br>
    <input id="lastname" class="text" type="text" name="lastname" /><br>
    <input id="email" class="text" type="text"  name="email" /><br>
    <input id="address" class="text" type="text" /><br>
    <input id="city" class="text" type="text"/><br>
    <input id="zipcode" class="text" type="text" maxlength="5" name="zipcode" /><br>
    <input type="submit" value="Send Me My FREE List" id="submitBtn2"/>
</form>

The problem is the input field get variables are causing your url get variables to be truncated, put all your url parameters as hidden values.

<input id="pub" type="hidden" name="pub" value=""/>
<input id="sid" type="hidden" name="sid" value=""/>

I'm assuming that you like the URL that it generates except that you're missing the sid, pub, c1, c2, c3, and append variables. If so, just make hidden inputs like this:

<form id="regForm" ...>
  <input id="sid" name="sid" value="" type="hidden" />
  <input id="pub" name="pub" value="" type="hidden" />
  ...
</form>

If you know the values while you're creating the form, then you can do it on the server side. If you don't, then assuming you're using jQuery, you will have to do something like this:

$(function() {
  $('#regForm').submit(function () {
    $('#sid').val('myNewSidValue');
    $('#pub').val('myNewPubValue');
    ...
  });
});

本文标签: phpAppend variables to url after form submitStack Overflow