-1
Imagine that I have a tagged URL, for example: https://meusite.com.br?utm_source=StackOverflow.
This would be the basic tagging, it also has the parameters utm_source, utm_medium, utm_campaign, utm_term and finally utm_content.
I made a code to pull these parameters and create variables (because I will use them elsewhere). The problem is that if the URL is with ALL parameters the code works normally. Now, if one is missing for example it gives error. I would need him to simply ignore the variable that he doesn’t have.
<?php
$url_atual = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$url_source = $_COOKIE['utm_source'] = $_GET['utm_source'];
$url_medium = $_COOKIE['utm_medium'] = $_GET['utm_medium'];
$url_campaign = $_COOKIE['utm_campaign'] = $_GET['utm_campaign'];
$url_term = $_COOKIE['utm_term'] = $_GET['utm_term'];
$url_content = $_COOKIE['utm_content'] = $_GET['utm_content'];
if(empty($url_content)) {
echo 'A variável está vazia';
}
else {
echo 'O valor da variável é: '.$url_content;
}
?>
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<title>Meu site</title>
</head>
<body>
<form action="enviar-lead.php" method="post">
<input type="text" name="nome" id="nome" placeholder="Nome:">
<input type="text" name="email" id="email" placeholder="E-mail:">
<input type="text" name="telefone" id="telefone" placeholder="Telefone:">
<textarea name="mensagem" id="mensagem" placeholder="Mensagem:"></textarea>
<input type="submit" class="btnContactDefault" name="btnEnviar" value="Enviar">
<input type="hidden" name="source" value="<?=($url_source)?>">
<input type="hidden" name="medium" value="<?=($url_medium)?>">
<input type="hidden" name="campaign" value="<?=($url_campaign)?>">
<input type="hidden" name="term" value="<?=($url_term)?>">
<input type="hidden" name="content" value="<?=($url_content)?>">
</form>
</body>
</html>
Use
if
andisset()
with every $_GET, this is the basics of "current" programming, the "Ifs"– Guilherme Nascimento
If one is missing, it would go as the variable value, empty ?
– Pedro Henrique
Or you could use a suit to return the null value.
– Glenys Mitchell
@Pedrohenrique, it could be empty. I’ve done it. Thank you.
– Mario
Thanks for the tip, @Guilhermenascimento
– Mario