0

I am trying to pre-populate a set of form fields by passing info via parameters in the URL. I have been able to do this with html forms before by simply adding the parameters to the URL, for example ?name=John. The variable I enter usually appears in the form field.

I am finding that this approach is not working on the latest form. I have been able to identify the parameter names but when I add them to the end of the URL they are not populated in to the form.

For example using website.co.uk/admin/usersearch.php?email=test@test.com I would expect the email field to be populated with test@test.com but the page refreshes and the form is still blank.

Is this because it is a .php form? Is there anyway round this? I only have the options to use the URL or javascript.

Thanks

KerryT
  • 1
  • 1

2 Answers2

1

Give your field value as <?php echo $_GET['email'];?>

Like this :

<input type="text" name="email" value="<?php echo $_GET['email'];?>" />
Prasanth Bendra
  • 31,145
  • 9
  • 53
  • 73
0

There is no such default procedure for pre-populating form fields built in to any web server. So, I'm not sure how you got it working earlier. Maybe the developer had actually coded it such that the form pre-population occurred.

For the new form, you could do as Prasanth suggested. However, since you require only JavaScript or HTML, refer to this prior question for further assistance: How to retrieve GET parameters from javascript?

Basically, what you'll be doing is getting the value of the field from the url and setting the field's value to it in the form using JavaScript.

Community
  • 1
  • 1
Ishbir
  • 286
  • 3
  • 11