Hi there,
Relatively new to EE, whilst ive read about add-ons, I would preferably just hard-code PHP as im used to into my templates.
I am trying to use variables from a URL to then echo them directly onto a form (to avoid users having to repeatedly type info)
i.e. https://www.exampleform.com?applicantFirstName=Chris
to get & echo: <?php $applicantFirstName=$_GET(applicantFirstName)?>
Then in the form field, the flwg to show and display the variable as the value <INPUT id=”applicantFirstName” type=”text” name=”applicantFirstName” value=’<?php echo $applicantFirstName ?>’>
How can the above be used in EE, i am using version 2.4
Clarification much appreciated !!
You’re pretty close. To grab the parameter (you might want to check that it exists first, using array_key_exists):
<?php $applicantFirstName = $_GET[‘applicantFirstName’]; ?>
Then to use it to populate the form:
<input type=”text” id=”applicantFirstName” name=”applicantFirstName” value=”<?php echo $applicantFirstName ?>”>
(Better to use double quotes.)
You should be able to put the code pretty much anywhere in your template. If what you have isn’t working, make sure that you’ve enabled PHP in the template. Go to the template preferences and check that “Allow PHP?” is set to yes.
Hi Paul, thanks for the reply.
I have tried your code but still no luck, I also tried using array_key_exists, and it does not (confused).. so theres a problem when im trying to use _GET method? any clues? I also have PHP active and at the moment it is on INPUT setting, is that how it should be?
Many thanks
If you’re not seeing the parameter in the $_GET array, this isn’t a PHP problem.
First thing: check what’s coming through in the $_GET array. Put this line right at the top of the template, and it will dump the contents of the $_GET array, so you can see what’s in it:
<?php print_r($_GET); ?>
If you don’t see the parameter in there, something might be going wrong with the URL you’re passing in. Could you post the exact URL you’re using?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.