A
A
adreanov2017-10-08 23:15:11
PHP
adreanov, 2017-10-08 23:15:11

How to pass a variable in a form handler?

There is a script for sending a form on the site, in addition to the name and phone fields, it is necessary that the value of utm tags be transmitted, this is how it is written and data on utm tags is not transmitted:

if ($_POST['data']['name']['value']){$body .= 'Имя: '.$_POST['data']['name']['value'].'<br />';}
if ($_POST['data']['phone']['value']){$body .= 'Телефон: '.$_POST['data']['phone']['value'].'<br />';}
if ($email){$body.= "utm_source: $utm_source<br />";}
if ($email){$body.= "utm_medium: $utm_medium<br />";}
if ($email){$body.= "utm_campaign: $utm_campaign<br />";}
if ($email){$body.= "utm_term: $utm_term<br />";}
if ($email){$body.= "utm_content: $utm_content<br />";}

and in another script, this is how it is written and successfully transmitted:
if ($name){$body.= "Имя: $name<br />";}
if ($phone){$body.= "Телефон: $phone<br />";}
if ($email){$body.= "utm_source: $utm_source<br />";}
if ($email){$body.= "utm_medium: $utm_medium<br />";}
if ($email){$body.= "utm_campaign: $utm_campaign<br />";}
if ($email){$body.= "utm_term: $utm_term<br />";}
if ($email){$body.= "utm_content: $utm_content<br />";}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Sklyarov, 2017-10-08
@0example

Add hidden fields to the form that will pull labels from the address bar:

<input type="hidden" name="utm_term" value="<?php echo isset($_GET['utm_term']) ? $_GET['utm_term'] : '' ;?>">
<input type="hidden" name="utm_campaign" value="<?php echo isset($_GET['utm_source']) ? $_GET['utm_campaign'] : '' ;?>">
<input type="hidden" name="utm_content" value="<?php echo isset($_GET['utm_content']) ? $_GET['utm_content'] : '' ;?>">
<input type="hidden" name="utm_source" value="<?php echo isset($_GET['utm_source']) ? $_GET['utm_source'] : '' ;?>">
<input type="hidden" name="utm_medium" value="<?php echo isset($_GET['utm_medium']) ? $_GET['utm_medium'] : '' ;?>">

The tags themselves in the script are pulled in the same way through $ _POST as a field value

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question