Home>

I'm trying to implement a completion screen in PHP
Even though I have entered the textarea part of html, the message (

You are required to input your message.

) at the time of the error of $message described in php is displayed on the completion screen. ..

If i don't understand the reason and can understand it, please do not hesitate to contact us.
I'm sorry if it's Pokamis.
If i do not have enough information, please let us know as we will add it.

<? php
$action = $_POST ['action'];
$name = htmlspecialchars ($_POST ['name'], ENT_QUOTES);
$email = htmlspecialchars ($_POST ['email'], ENT_QUOTES);
$tel = htmlspecialchars ($_POST ['phone'], ENT_QUOTES);
$azarashi = htmlspecialchars ($_POST ['message'], ENT_QUOTES);
$error ='';
if ($name =='') {
    $error = $error.'<P>You are required to input your name.</p>';
}
if ($email =='') {
    $error = $error.'<P>You are required to input your email adress.</p>';
}
if ($message =='') {
    $error = $error.'<P>You are required to input your message.</p>';
}
if ($error! ='') {
    echo $error;
    echo'<form method = "POST" action = "index.html">';
    echo'<input type = "submit" name = "backbtn" value = "return to previous page">';
    echo'</form>';
} else {
    $mail. = "Following message was sent successfully. \ N \ n";
    $mail. = "name \ n";
    $mail. = $name. "\ n \ n";
    $mail. = "email \ n";
    $mail. = $Email. "\ n \ n";
    $mail. = "telephone \ n";
    $mail. = $phone. "\ n \ n";
    $mail. = "message \ n";
    $mail. = $message. "\ n \ n";
    $mail_to = "[email protected]";// Destination email address
    $mail_subject = "";// Email subject
    $mail_body = $mail;// Email body
    $mail_header = "from:". $Email;// Display the email address entered in the form as the sender
    $mailsend = mb_send_mail ($mail_to, $mail_subject, $mail_body, $mail_header);
    if ($mailsend == true) {
        echo'<p>An email has been sent.</p>';
        echo'<form method = "post" action = "form.html">';
        echo'<input type = "submit" name = "backbtn" value = "return to previous page">';
        echo'</form>';
    } else {
        echo'<p>An error occurred while sending an email.</p>';
        echo'<form method = "post" action = "form.html">';
        echo'<input type = "submit" name = "backbtn" value = "return to previous page">';
        echo'</form>';
    }
}
?>
<form method = "POST" action = "./confirm.php">
                      <input type = "text" name = "name" placeholder = "Name" autocomplete = "off" required = "required">
                         
                      <input type = "text" name = "email" placeholder = "Email" autocomplete = "off" required = "required">
                         
                      <input type = "text" name = "phone" placeholder = "Telephone" autocomplete = "off">
                         
                      <textarea name = "message" placeholder = "We'd love to hear your voice!" autocomplete = "off"></textarea>
                      <input type = "submit" value = "SEND TO US">
                  </form>
  • Answer # 1

    if ($message =='') {
    Judging by, $message is not defined anywhere.

    $azarashi = htmlspecialchars ($_POST ['message'], ENT_QUOTES);

    $azarashi ...?

    Also, htmlspecialchars () is done when the screen is output, and should not be done when the request is received.
    Even if you validate it, the information will be processed, so it will not play the role of validation.