rocksause
rocksause

Reputation: 111

How to use the $_GET function to pull URL data?

I am trying to understand how to use the $_GET function. I am using a form from my CRM system Infusionsoft. I have a few different ads running to this form from different sources. I use UTM's to keep track of where people are coming from.

Example URL UTM: http://www.awesome.com/?utm_source=google&utm_medium=cpc&utm_term=keywords&utm_content=content&utm_campaign=name

The hidden field was my attempt to try to pull the data and pass it along when the form is submitted. Unfortunately it is not working and I am a bit of a newbie to php.

<form accept-charset="UTF-8" action="https://mk165.infusionsoft.com/app/form/process/ff023ed2f8ffd7c46b03cdc50a115e93" class="infusion-form" method="POST" name="myForm" onsubmit="return validateForm()">

<input name="inf_form_xid" type="hidden" value="ff023ed2f8ffd7c46b03cdc50a115e93" />


  <input name="inf_form_name" type="hidden" value="Ninh Neuropathy" />
  <input name="infusionsoft_version" type="hidden" value="1.48.0.46" /> 
    <input type="hidden" id="inf_custom_GaSource" name="inf_custom_GaSource" value='<?php echo $_GET['utm_source']?>'/>
    <input type="hidden" id="inf_custom_GaMedium" name="inf_custom_GaMedium" value='<?php echo $_GET['utm_medium']?>'/>
    <input type="hidden" id="inf_custom_GaTerm" name="inf_custom_GaTerm" value='<?php echo $_GET['utm_term']?>'/> 
    <input type="hidden" id="inf_custom_GaCampaign" name="inf_custom_GaCampaign" value='<?php echo $_GET['utm_campaign']?>'/> 
    <input type="hidden" id="inf_custom_GaContent" name="inf_custom_GaContent" value='<?php echo $_GET['utm_content']?>'/>
  <input class="infusion-field-input-container" placeholder="First Name" name="inf_field_FirstName" type="text" />
  <input class="infusion-field-input-container" placeholder="Last Name" name="inf_field_LastName" type="text" />
  <input class="infusion-field-input-container" placeholder="Phone" name="inf_field_Phone1" type="text" />	
  <input class="infusion-field-input-container" placeholder="E-mail" name="inf_field_Email" type="text" />
  <input class="infusion-field-input-container submit" id="submit" name="" value="Get In Touch Today" type="submit" />


</form>

Upvotes: 1

Views: 629

Answers (2)

hherger
hherger

Reputation: 1680

Often both types of parameters are needed. It might make things easier if GET and POST parameters are normalized and then can be accessed in a unique way like this:

$params = array();
foreach ($_GET as $k=> $v)  $params [$k] = $v;
foreach ($_POST as $k=> $v) $params [$k] = $v;

echo $params['myvalue'];

Upvotes: 0

devpro
devpro

Reputation: 16117

Your form method is POST so when you submit the form you will get the values in php as:

<?php

print_r($_POST);

?>

You will get the all form input values in $_POST Super Global included all hidden inputs.

One last thing also use double quotes in hidden input values instead of single quotes as:

<input type="hidden" id="inf_custom_GaSource" name="inf_custom_GaSource" value="<?php echo $_GET['utm_source'];?>"/>

Upvotes: 0

Related Questions