Error messages are not displayed under the corresponding input fields. Use HTML, PHP-PHP Chinese Network Q&A
Error messages are not displayed under the corresponding input fields. Use HTML, PHP
P粉567112391
P粉567112391 2023-09-15 15:05:59
0
1
396

If the user enters invalid data, how to immediately display the corresponding error message under the input field. For example, the user enters invalid data in the Name field and an error message immediately appears under the Name field. The same goes for the Email and Message fields. I'm using the next HTML and PHP code:

SMTPDebug = SMTP::DEBUG_SERVER; $mail->isSMTP(); $mail->SMTPAuth = true; $mail->Host = "smtp.gmail.com"; $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; $mail->Port = 587; require_once 'config.php'; $mail->Username = SMTP_USERNAME; $mail->Password = SMTP_PASSWORD; $mail->setFrom($emailSanitized, $nameSanitized); $mail->addAddress("myemail@gmail.com", "myemail"); $mail->Subject = $subject; $mail->Body = "Name: $nameSanitized\nEmail: $emailSanitized\n\n$messageSanitized"; $mail->send(); header("Location: sent.html"); } catch (Exception $e) { echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo; } } else { echo $emailErr; echo $nameErr; echo $messErr; } ?>

I tried different articles.

P粉567112391
P粉567112391

reply all (1)
P粉391677921

Put the HTML code into anelseblock

} else { ?> 
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!