Browno Browno - 5 months ago 16
SQL Question

Pre fill form using the URL bar

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.

Answer

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;">
Comments