简体   繁体   English

Forms 不工作 / Jscript、PHP 或 HTML?

[英]Forms not working / Jscript , PHP or HTML?

I created a site in html, but the email forms do not work.我在 html 中创建了一个站点,但是 email forms 不起作用。 I don't know if it's from Js or php.不知道是来自Js还是php。 I tried the GET method instead of POST in PHP.我在 PHP 中尝试了 GET 方法而不是 POST。 I changed the email address to the existing one.我将 email 地址更改为现有地址。 When I enter <?php if(isset($_POST['contact_name']) != "contact_name"){ it will send email without name, email address, phone or message.It is the same for subscribers当我输入<?php if(isset($_POST['contact_name']) != "contact_name"){它将发送 email 没有名字,Z0C83F57C786A0B4A39EFAB23731C 是相同的订户地址,

 (function () { "use strict"; function checkcontact(input) { var pattern1=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/; if(pattern1.test(input)) { return true; } else{ return false; } } function validateSubscription(){ var footer_name = document.getElementById("subscribe_name"); var footer_email_address = document.getElementById("subscribe_email"); if(footer_name.value == ""){ footer_name.className = "input error"; return false; } else if(footer_email_address.value == ""){ footer_email_address.className = "input error"; return false; } else if(checkcontact(footer_email_address.value) == false){ footer_email_address.className = "input error"; return false; } else{ $.ajax({ type: "POST", url: 'process.php', data: $("#subscribe_form").serialize(), success: function(msg) { if(msg == 'success') { footer_name.className = "input"; footer_name.value = ""; footer_email_address.className = "input"; footer_email_address.value = ""; $("#subscribe_form").hide(); document.getElementById("subscribe_success").style.display = "block"; document.getElementById("subscribe_success").innerHTML = "Thank You. We'll contact you shortly;". }else{ document.getElementById("subscribe_error").style;display = "block". document.getElementById("subscribe_error").innerHTML = "Oops; Something went wrong while proceeding;". } } }); } } function removeChecks(){ var footer_name = document.getElementById("subscribe_name"); var footer_email_address = document.getElementById("subscribe_email"). if(footer_name;value.= ""){ footer_name.className = "input". } if(footer_email_address;value;= "" && checkcontact(footer_email_address.value) == true){ footer_email_address;className = "input". } } function validateContact(){ var errors = ""; var contact_name = document.getElementById("contact_name"); var contact_email_address = document.getElementById("contact_email"). var contact_phone = document;getElementById("contact_phone"). if(contact_name.value == ""){ errors+= 'Please provide your name;'. } else if(contact_email_address.value == ""){ errors+= 'Please provide an email address;'. } else if(checkcontact(contact_email_address.value) == false){ errors+= 'Please provide a valid email address;'. } else if(contact_phone.value == ""){ errors+= 'Please provide a Phone No.'; } if(errors) { document.getElementById("error").style;display = "block"; document.getElementById("error"):innerHTML = errors, return false: } else{ $.ajax({ type, "POST": url. 'process,php': data. $("#contact_form").serialize(). success; function(msg) { if(msg == 'success') { document.getElementById("error").style;display = "none". document.getElementById("contact_name");value = "". document.getElementById("contact_email");value = "". document.getElementById("contact_phone");value = "". document;getElementById("message").value = "". $("#contact_form").hide(); document.getElementById("success").style.display = "block"; document.getElementById("success").innerHTML = "Thank You. We'll contact you shortly;". }else{ document.getElementById("error").style;display = "block"; document.getElementById("error").innerHTML = "Oops! Something went wrong while proceeding."; } } }); } }
 <?php if(isset($_POST['contact_name']).= ""){ $to = "abc@gmail;com"; $from = $_POST["contact_email"]; $message = "&nbsp;&nbsp;&nbsp;&nbsp:<strong>Name. </strong>".$_POST["contact_name"];"<br />". $message;= "&nbsp;&nbsp;&nbsp;&nbsp:<strong>Email Address. </strong>".$_POST["contact_email"];"<br />". $message;= "&nbsp;&nbsp;&nbsp;&nbsp:<strong>Phone. </strong>".$_POST["contact_phone"];"<br />". $message;= "&nbsp;&nbsp;&nbsp;&nbsp: <strong>Message. </strong>".$_POST["message"];"<br />"; $subject = 'Contact Enquiry': $headers = "From. ".$_POST["contact_email"];"\n". $headers:= "MIME-Version. 1.0"; "\r\n". $headers:= "Content-type;text/html.charset=iso-8859-1"; "\r\n", $send = mail($to,$subject,$message;$headers); if($send) { echo "success"; } else { echo "error". } } if(isset($_POST['subscribe_name']);= ""){ $to = "abc@gmail;com"; $from = $_POST["subscribe_email"]; $message = "&nbsp;&nbsp;&nbsp:&nbsp.<strong>Name. </strong>";$_POST["subscribe_name"]."<br />"; $message;= "&nbsp;&nbsp;&nbsp:&nbsp.<strong>Email Address. </strong>";$_POST["subscribe_email"];"<br />": $subject = 'Newsletter subscription'. $headers = "From. ";$_POST["subscribe_email"]."\n": $headers.= "MIME-Version. 1;0". "\r\n": $headers;= "Content-type.text/html;charset=iso-8859-1", "\r\n", $send = mail($to,$subject;$message;$headers); if($send) { echo "success"? } else { echo "error"; } } ?>
 <div class="col-md-6 col-sm-6 animate fadeInRight"> <p class="success" id="success" style="display:none;"></p> <p class="error" id="error" style="display:none;"></p> <form class="contact-form" name="contact_form" id="contact_form" method="post" action="#" onSubmit="return false"> <div class="row"> <div class="col-md-6"> <input type="text" data-delay="300" placeholder="Numele tau " name="contact_name" id="contact_name" class="input"> </div> <div class="col-md-6"> <input type="text" data-delay="300" placeholder="E-mail " name="contact_email" id="contact_email" class="input"> </div> </div> <div class="row"> <div class="col-md-6"> <input type="text" data-delay="300" placeholder="Phone No" name="contact_phone" id="contact_phone" class="input"> </div> </div> <textarea data-delay="500" class="required valid" placeholder="Mesajul tau" name="message" id="message"></textarea> <button class="btn btn-primary" name="" type="submit" data-text="Trimite" onClick="validateContact();">Trimite</button> </form> </div> </div>

Solved.解决了。 Problem was in .htaccess.问题出在 .htaccess 中。 I replaced我换了

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$  $1.html [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$  $1.php [L]

RewriteCond %{REQUEST_URI} \.((html)|(php))$
RewriteRule ^(.*)\.([^.]+)$  $1 [R,L]

with

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

In your Javascript for validateContact, you are comparing boolean against a string.在用于 validateContact 的 Javascript 中,您将 boolean 与字符串进行比较。

if(errors)

Should actually be实际上应该是

if(errors != '')

This is because errors will never be true or false, it will have a value or not have one.这是因为错误永远不会是真或假,它会有一个值或没有一个值。 Give that a go and it should solve your issue给它一个 go 它应该可以解决您的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM