1

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>
devpro
  • 16,184
  • 3
  • 27
  • 38
rocksause
  • 111
  • 1
  • 6
  • you used method post.. then you have to use `$_POST` if you want to use `$_GET` change your attribute methode to get `method="GET"` – Pierre-Luc Bolduc Jan 19 '16 at 19:24
  • When u submit the form u will get all values in $_POST in php – devpro Jan 19 '16 at 19:24
  • `$_GET` is not a function, it is an array containing parameters from an HTTP `GET` request. Your form specifies `method="POST"` so the request is a `POST` and the form data will be in the `$_POST` array. – Sammitch Jan 19 '16 at 19:26
  • @pbolduc Ah thank you! Is there a way to use both $_POST and $_GET? Or, is there a better solution? – rocksause Jan 19 '16 at 19:31
  • 1
    @rocksause You can use `$_REQUEST`, it combines all the POST and GET parameters into one array. – Barmar Jan 19 '16 at 19:31
  • @rocksause - I think these people are a little confused. You want to use `$_GET` from the query string in the URL and pass them to the hidden inputs. You put in the query string, but the hidden inputs don't show anything? Have you tried viewing your page source to see if indeed the values of the input are in fact the same as the parameters you put in the URL? – Paul Carlton Jan 19 '16 at 19:32
  • @rocksause see this link http://stackoverflow.com/questions/504947/when-should-i-use-get-or-post-method-whats-the-difference-between-them it will help you to understand different between GET and POST request. And no you can't use both GET and POST – Pierre-Luc Bolduc Jan 19 '16 at 19:34
  • @DataHerder I just viewed the page source and actually the correct values from the URL are there. Do you think the fact that the form has both GET and POST is keeping it from working, or is it on the receiving side with my CRM system Infusionsoft? – rocksause Jan 19 '16 at 19:50
  • @rocksause - at this point I think it's HIGHLY likely it's on the receiving end of the CRM system. But FYI - the form does not have both `GET` and `POST`, you are using the URL query string, utilizing GET, to make those hidden inputs POST the GET parameters you are specifying to the CRM system. Now with that said, yes I think it's very much likely that it's on the receiving end. You are posting those variables now, it's a matter of having the CRM recognize them. – Paul Carlton Jan 19 '16 at 19:58

2 Answers2

0

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'];?>"/>
devpro
  • 16,184
  • 3
  • 27
  • 38
0

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'];
hherger
  • 1,660
  • 1
  • 10
  • 13
  • They are already “normalized” in `$_REQUEST`. And usually one should know _where_ one expects parameters from (exceptions exist.) But apart from re-creating already existing functionality, yours has the added disadvantage that `$params` is not superglobal, so it would have to be passed into every single function that wants to use those values. – CBroe Jan 19 '16 at 20:53