-3

I have a form which I need it to insert data using the URL first for a few fields. I've attached a sample of my form below. We're posting it using PHP into a mySQL database. I don't mind how it gets in there. But i've seen examples using example.com/form.php?add_1=10 The Street, which would be the best way for me.

Thanks,

<form role="form" method="post" action="<?php $_SERVER['PHP_SELF'] ?>" name="epicform">
<input type="text" class="form-control" id="lastname" name="surname" required style="
height: 35px;
">
<input type="text" class="form-control" id="add_1" name="add1" placeholder="Address Line 1" required style="
height: 35px;
">
<input type="text" class="form-control" id="add_2" name="add2" placeholder="Address Line 2" required style="
height: 35px;
">
<input type="text" class="form-control" id="add_3" name="add3" placeholder="Address Line 3" required style="
height: 35px;
">
<input type="text" class="form-control" id="postcode" name="postcode" placeholder="Postcode" required style="
height: 35px;
">
<input type="text" class="form-control" id="phone_number" name="phoneNum" placeholder="Phone Number" required style="
height: 35px;
">
</form>

I've already tried a javascript solution on here, but I couldn't seem to get it to do anything.

Browno
  • 41
  • 1
  • 7
  • 5
    Questions asking for code should **demonstrate a minimal understanding of the problem being solved**. Include attempted solutions, why they didn't work, and the expected results. See also: [Stack Overflow question checklist](http://meta.stackexchange.com/questions/156810/stack-overflow-question-checklist). – John Conde Apr 25 '14 at 12:51
  • I have already tried http://stackoverflow.com/questions/14070105/pre-fill-form-field-via-url-in-html but i can't seem to get it to do anything! – Browno Apr 25 '14 at 12:58
  • @JohnConde Whatever happened to that closing option? That was the best one ever. (*I see you've archived it*) ;-) SO should put it back in. +1 (I think I'll keep a copy of it myself). – Funk Forty Niner Apr 25 '14 at 13:04
  • 1
    I liked it, too, but SO felt there were better ways of doing this. I think this ones sums up the problem *nicely*. Hence, I still use it. – John Conde Apr 25 '14 at 13:05
  • Yes it does sum it up quite *nicely.* @JohnConde I'm saving it for future use. – Funk Forty Niner Apr 25 '14 at 13:05

2 Answers2

1
<form role="form" method="post" action="<?php $_SERVER['PHP_SELF'] ?>" name="epicform">

<input type="text" class="form-control" id="add_1" name="add1" value="<?php echo $_GET['add1']; ?>" placeholder="Address Line 1" required style="height: 35px;">

</form>

Now your URL must work! http://example.com/form.php?add_1=10

Tech
  • 11
  • 3
0

What you need is this: http://www.php.net/manual/en/reserved.variables.get.php

http://urlToYourScript.php?add1=Randomstreet

<input type="text" class="form-control" id="add_1" name="add1" 
placeholder="<?php echo $_GET['add1']; ?>" required style="height: 35px;">
VF_
  • 2,627
  • 17
  • 17