此表单的开发是在同一页面上发送数据。
我想在发送和显示消息时隐藏联系表单,例如:感谢您与我们联系。
我提出的问题是,当您执行发送操作时,表单会被隐藏并显示错误消息,但联系表单仍然是隐藏的。
<!DOCTYPE html>
<html>
<head>
<title>Contact US</title>
</head>
<body>
<?php
session_start();
$errors = '';
$nombre = '';
$email = '';
$telefono = '';
$mensaje = '';
if(isset($_POST['submit'])) {
if($_SESSION['vcode'] != $_POST['vcode']) {
$errors .= "The characters do not match the captcha code";
}
$nombre = $_POST["name"];
$email = $_POST["mail"];
$telefono = $_POST["phone"];
$mensaje = $_POST["message"];
if(empty($nombre)) {
$errors .= "\n Please enter your name. ";
}else {
if (!preg_match("/^[a-zA-Z ]*$/",$nombre)) {
$errors .= "\n Only letters and spaces are allowed.";
}
}
if(empty($email)) {
$errors .= "\n Please enter your email. ";
}else{
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors .="\n Invalid email";
}
}
if(empty($telefono)) {
$errors .= "\n Please enter your phone number. ";
}else{
if(!preg_match("/^\+?\d{1,3}?[- .]?\(?(?:\d{2,3})\)?[- .]?\d\d\d[- .]?\d\d\d\d$/", $telefono)) {
$errors .="\n Invalid number";
}
}
if($_POST['producto'] == 0){
$errors .= "\n You must select a product";
}
if(empty($mensaje)) {
$errors .= "\n Please enter your message. ";
}
if(empty($errors)) {
$asunto = "";
$message = "Usuario:".$_POST['name']." Email:".$_POST['mail']." Telefono ".$_POST['phone']." Informacion ".$_POST['message'];
$destino = "contacto@example.com";
$remitente = "From: contacto@example.com";
mail($destino,$asunto,$message,$remitente);
unset($_POST['submit']);
echo "Thanks for your comments";
}
}
?>
<div class="error">
<?php
if(!empty($errors)){
echo "<p class='err'>".nl2br($errors)."</p>";
}else{
?>
</div>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" autocomplete="off" enctype="multipart/form-data">
<div class="touch">
<div class="name">
<input type="text" name="name" placeholder="Name" value='<?php echo htmlentities($nombre) ?>'>
</div>
<div class="email">
<input type="text" name="mail" placeholder="Email" value='<?php echo htmlentities($email) ?>'>
</div>
<div class="phone">
<input type="tel" name="phone" placeholder="Phone" value='<?php echo htmlentities($telefono) ?>'>
</div>
<div class="select-pro">
<select name="producto">
<option value="0" selected>Affair...</option>
<option value="1">Product 1</option>
<option value="2">Product 2<option>
<option value="3">Product 3</option>
<option value="4">Other</option>
</select>
</div>
<div class="Customer-message">
<textarea id="message" name="message" placeholder="Su consulta..."><?php echo htmlentities($mensaje) ?></textarea>
</div>
<div class="capcha">
<img src="image.php" name="vcode" id="phoca-captcha"/>
<input name="vcode" type="text" placeholder="Codigo captcha">
</div>
<input type="submit" name="submit" value="Enviar">
</div>
</form>
<?php } ?>
</body>
</html>
答案 0 :(得分:1)
if($_SERVER['REQUEST_METHOD'] == 'POST'){
//ur php code (allways use ) $_SERVER['REQUEST_METHOD']
}else{
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" autocomplete="off" enctype="multipart/form-data">
<div class="touch">
<div class="name">
<input type="text" name="name" placeholder="Name" value='<?php echo htmlentities($nombre) ?>'>
</div>
<div class="email">
<input type="text" name="mail" placeholder="Email" value='<?php echo htmlentities($email) ?>'>
</div>
<div class="phone">
<input type="tel" name="phone" placeholder="Phone" value='<?php echo htmlentities($telefono) ?>'>
</div>
<div class="select-pro">
<select name="producto">
<option value="0" selected>Affair...</option>
<option value="1">Product 1</option>
<option value="2">Product 2<option>
<option value="3">Product 3</option>
<option value="4">Other</option>
</select>
</div>
<div class="Customer-message">
<textarea id="message" name="message" placeholder="Su consulta..."><?php echo htmlentities($mensaje) ?></textarea>
</div>
<div class="capcha">
<img src="image.php" name="vcode" id="phoca-captcha"/>
<input name="vcode" type="text" placeholder="Codigo captcha">
</div>
<input type="submit" name="submit" value="Enviar">
</div>
</form>
}
答案 1 :(得分:0)
试试这个!
closestNumbers(newarr)
答案 2 :(得分:0)
更新您的代码:
//I am using write now this can possible
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
Intent notificationIntent = new Intent(context, HomeActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
Regrads:)