HTML から PHP ページに隠し変数を渡しています。PHP ページでは、その変数をフォームで使用したいと考えています。
<?php
$newVar=trim($_POST['newVar']);
$subject = "new var is ---> $newVar";
?>
$newVar
どのif
ステートメントでも使用できません- 空白と表示されます。をエコー$subject
しようとすると、 の値が表示されますが、任意のステートメントで$newVar
の値をエコーしようとすると、 の値が表示されません。$subject
if
$newVar
私のコードは: html マークアップは:
<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 = "test@test.com";
$emailTo = 'shruti@example.com';
$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 = "do-not-reply@example.com";
$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";
}
?>