У меня есть подтверждение для моей контактной формы, которая добавляет красный текстовый шрифт под требуемыми входами. Но то, что я действительно хочу, - это добавить красную рамку внизу к входу, чтобы показать, что это необходимо. У меня есть уже работающий PHP-коммутатор, но я не могу найти ответ в любом месте, чтобы добавить классы css в разные случаи. Надеюсь, кто-то знает об этом больше, чем я.php switch case to change css class
Вот мой PHP
<?php
session_start();
// define variables and set to empty values
$nameErr = $emailErr = $phoneErr = $humanErr = "";
$Name = $Email = $Phone = $Human = "";
$hasError = false;
$sent = false;
if(isset($_POST['submit'])) {
$Name = trim(htmlspecialchars($_POST['Name'], ENT_QUOTES));
$FName = trim($_POST['FiancesName']);
$Email = trim($_POST['Email']);
$DesiredWedDate = trim($_POST['DesiredWedDate']);
$WeddingSize = trim($_POST['WeddingSize']);
$Phone = trim($_POST['Phone']);
$IndoorCeremony = trim($_POST['IndoorCeremony']);
$OutdoorCeremony = trim($_POST['OutdoorCeremony']);
$AlcoholYes = trim($_POST['AlcoholYes']);
$AlcoholNo = trim($_POST['AlcoholNo']);
$Human = trim($_POST['Human']);
$Number = 6;
$fieldsArray = array(
'Name' => $Name,
'Email' => $Email,
'Phone' => $Phone,
'Human' => $Human
);
$errorArray = array();
foreach($fieldsArray as $key => $val) {
switch ($key) {
case 'Name':
if(empty($val)) {
$hasError = true;
$nameErr = "Please enter your name.";
}
case 'Name':
if (!preg_match("/^[a-zA-Z ]*$/", ($val))) {
$hasError = true;
$nameErr = "The value must be alphanumeric.";
}
break;
case 'Phone':
if (!preg_match("/^[0-9]+$/", ($val))) {
$hasError = true;
$phoneErr = "Only numbers and white space allowed.";
}
case 'Phone':
if(empty($val)) {
$hasError = true;
$phoneErr = "Phone is required.";
}
break;
case 'Email':
if(!filter_var($Email, FILTER_VALIDATE_EMAIL)) {
$hasError = true;
$emailErr = "Email is required.";
} else {
$Email = filter_var($Email, FILTER_SANITIZE_EMAIL);
}
break;
case 'Human':
if (!preg_match("/[^\d]?6[^\d]?/", ($val))) {
$hasError = true;
$humanErr = "Not the right answer";
}
case 'Human':
if (!preg_match("/^[0-9]+$/", ($val))) {
$hasError = true;
$humanErr = "Must be a number";
}
case 'Human':
if(empty($val)) {
$hasError = true;
$humanErr = "Are you human?";
}
break;
}
}
//CHECK BOX WRITE UP
if (isset($_POST['IndoorCeremony'])) {
$checkBoxValue = "yes";
//is checked
} else {
$checkBoxValue = "no";
//is unchecked
}
if (isset($_POST['OutdoorCeremony'])) {
$checkBoxValue = "yes";
//is checked
} else {
$checkBoxValue = "no";
//is unchecked
}
if (isset($_POST['AlcoholYes'])) {
$checkBoxValue = "yes";
//is checked
} else {
$checkBoxValue = "no";
//is unchecked
}
if (isset($_POST['AlcoholNo'])) {
$checkBoxValue = "yes";
//is checked
} else {
$checkBoxValue = "no";
//is unchecked
}
//Validation Success!
//Do form processing like email, database etc here
if($hasError !== true) {
$priority = $_POST['priority'];
$type = $_POST['type'];
$message = $_POST['message'];
//FOR STYLING EMAIL
// $headers .= "MIME-Version: 1.0" . "\r\n";
//$headers .= "Content-Type: text/html; charset=UTF-8" . "\r\n";
//STYLING EMAIL
/* $message = "<html>
<h1>
$Name
</h1>
<BR>
<h3>
$Email
<BR>Tel: $Phone
<BR>Company: $Compnay
<BR>Website: $Website
<BR>Subject: $Subjectmatter
<BR>Describe: $Describe
</h3>
<BR>
<BR>
<BR><h4>Web Design: $webdesign
<BR>Web Hosting: $webhosting
<BR>Wordpress Design: $wordpressdesign
<BR>Logo Design: $logodesign
<BR>Brochures: $brochures</h4>
<BR>
<BR>
<h4>
Other: $otherswitch
<BR>Describe: $OtherDescribe
</h4>
</html>";
*/
$formcontent=" From: $Name \n \n Fiance's Name: $FName \n \n Email: $Email \n \n Phone: $Phone \n \n Desired Wedding Date: $DesiredWedDate \n \n Wedding Size: $WeddingSize \n \n Describe: $Describe \n \n Indoor Ceremony: $IndoorCeremony \n \n Outdoor Ceremony: $OutdoorCeremony \n \n Alcohol Yes: $AlcoholYes \n \n Alcohol No $AlcoholNo \n \n Referral: $Referral \n ";
$recipient = "[email protected]";
$subject = "Pre Book Wedding Contact Form";
$mailheader = "From: $Email \r\n";
mail($recipient, $subject, $formcontent, $mailheader /*$message, $headers*/);
header("Refresh:0; url=thanks.php");
exit();
}
}
?><!--END PHP-->
Вот мой вход форма
<span class="input input--kaede">
<input name="FiancesName" class="input__field input__field--kaede" type="text" id="input-2" />
<label class="input__label input__label--kaede" for="input-2">
<span class="input__label-content input__label-content--kaede">Fiance's Name</span>
</label>
</span>
устанавливаемыми сотовыми Я хочу добавить я назвал его
.under_text_error {
border-bottom: 2px solid red;
}
, что следует надеяться, дать кому-то достаточно уйти. Я ценю любую возможную помощь!
хорошо, что работает, но проблема в том, когда я отправляю. Красная подсветка и внутренний вход исчезают. –
извините..может ли прояснить ... что это значит? – affaz
да нет проблема. Я добавил этот код между классом span и именем ввода. Теперь, когда я нажимаю submit, появляется красная подсветка. Когда я заполняю информацию и повторно передаю, линия все еще остается, и введенная информация исчезает. –