I am passing a hidden variable from HTML to a PHP page. In the PHP page I want to use that variable in my form.
<?php
$newVar=trim($_POST['newVar']);
$subject = "new var is ---> $newVar";
?>
I am not able to use $newVar in any if statement - it shows blank. If I try to echo $subject, it shows the value of $newVar but when I try to echo the value of $subject in any if statement it does not show me the value of $newVar.
My Code is: html markup is:
<a href="#" class="applyNow" onclick="document.sendVar.newVar.value='myVar'; document.sendVar.submit(); return false">New Variable</a>
<form method="post" name="sendVar" action="test.php" style="display:none;">
<input type="hidden" name="newVar" value="">
<input type="submit" value="Send form!">
</form>
php:
<?php
$newVar=trim($_POST['newVar']);
$subject = "new var is ---> $newVar";
?>
if(isset($_POST['submit'])) {
if(!isset($hasError)) {
$from_add = "[email protected]";
$emailTo = '[email protected]';
$headers = "From: $from_add \r\n";
$headers .= "Reply-To: $from_add \r\n";
$headers .= "Return-Path: $from_add\r\n";
$headers .= "X-Mailer: PHP \r\n";
mail($emailTo, $subject, $headers);
// HERE in $subject.. value of newVar is not displaying
$emailSent = true;
}
$from_add = "[email protected]";
$headers = "From: $from_add \r\n";
$headers .= "Reply-To: $from_add \r\n";
$headers .= "Return-Path: $from_add\r\n";
$headers .= "X-Mailer: PHP \r\n";
}
?>