passing variables from included html file to another php script
-
24-06-2021 - |
Pregunta
1.php
include'form.html'
form.html
<form action="email.php" method="post">
<input type="text" id="name" value="name" />
</form>
email.php
<?php
$name = $_POST['name'];
$email_message = "Name: $name ";
$sent = mail($email_to, $email_subject, $email_message);
if($sent) {
echo "success=yes";
} else {
echo "success=no";
}
include('success.html');
?>
error:
Notice: Undefined index: name in C:\wamp\www\a\action.php on line 3
I also tried making them global variables in form.html but not working
Solución
insert name="name" input tag of the form. like this
<input type="text" id="name" value="name" name="name" />
The name attribute specifies the name of an element. The name attribute is used to reference elements in a JavaScript, or to reference form data after a form is submitted. Only form elements with a name attribute will have their values passed when submitting a form.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow