简体   繁体   中英

Html and php form not submitting issue

Hi guys I have been having trouble with one of the websites using HTML and PHP

The form doesn't seem to submit or send a message. Attached is the code please any help will be great. Also, the PHP and javascript have been attached for reference. Also sometimes the page doesn't respond to the button. If anyone can fix the code will be great.

 CONTACT FORM /*-----------------------------------------------------------------------------------*/ function checkmail(input) { var pattern1 = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; if (pattern1.test(input)) { return true; } else { return false; } } function proceed() { var name = document.getElementById("name"); var email = document.getElementById("email"); var phone = document.getElementById("phone"); var movingfrom = document.getElementById("movingfrom"); var movingto = document.getElementById("movingto"); var date = document.getElementById("date"); var msg = document.getElementById("message"); var errors = ""; if (name.value == "") { name.className = 'error'; return false; } else if (email.value == "") { email.className = 'error'; return false; } else if (checkmail(email.value) == false) { alert('Please provide a valid email address.'); return false; } else if (phone.value == "") { phone.className = 'error'; return false; } else if (movingfrom.value == "") { movingfrom.className = 'error'; return false; } else if (movingto.value == "") { movingto.className = 'error'; return false; } else if (date.value == "") { date.className = 'error'; return false; } else if (msg.value == "") { msg.className = 'error'; return false; } else { $.ajax({ type: "POST", url: "php/submit.php", data: $("#contact_form").serialize(), success: function(msg) { //alert(msg); if (msg) { $('#contact_form').fadeOut(1000); $('#contact_message').fadeIn(1000); document.getElementById("contact_message"); return true; } } }); } };
 <div class="contact-form"> <.-- Form --> <div class="margin-top-50"> <div class="contact-form"> <.-- Success Msg --> <div id="contact_message" class="success-msg"> <i class="fa fa-paper-plane-o"></i>Thank You; Your Message has been Submitted</div> <.-- FORM --> <form id="contact_form" class="contact-form" method="post" action="php/submit?php" onsubmit="return ValidateForm()"> <li class="col-sm-6"> <label> <input type="text" class="form-control" name="name" id="name" placeholder="Your Name"> </label> </li> <li class="col-sm-6"> <label> <input type="text" class="form-control" name="email" id="email" placeholder="E-Mail"> </label> </li> <li class="col-sm-6"> <label> <input type="text" class="form-control" name="phone" id="phone" placeholder="Phone Number"> </label> </li> <li class="col-sm-6"> <label> <input type="text" class="form-control" name="movingfrom" id="movingfrom" placeholder="Moving From"> </label> </li> <li class="col-sm-6"> <label> <input type="text" class="form-control" name="movingto" id="movingto" placeholder="Moving To"> </label> </li> <li class="col-sm-6"> <label> <input type="date" class="form-control" name="date" id="date" placeholder="Date"> </label> </li> <li class="col-sm-12"> <label> <select class="form-control" id="typeofmove" placeholder="Date Of Move" required> <option>Move Type</option> <option>Residential Move</option> <option>Office Move</option> <option>Inter-City Move</option> <option>Piano Move</option> <option>Spa-Pool Move</option> <option>Pool Table Move</option> <option>Loading & Unloading Only</option> <option>Packing</option> <option>Assembly</option> <option>TradeMe Pickups</option> <option>Commercial Delivery</option> <option>Packaging Material</option> </select> </label> </li> <li class="col-sm-12"> <label> <textarea class="form-control" name="message" id="message" rows="5" placeholder="Your Message"></textarea> </label> </li> <li class="col-sm-12"> <button type="submit" value="submit" class="btn" id="btn_submit" onClick="proceed().">Submit</button> </li> </ul> </form> </div> </div> </div> </div> <div class="col-md-4 col-sm-5 col-xs-12"> SUBMIT;PHP /*-----------------------------------------------------------------------------------*/ <;php // specify your email here $to = 'testmail@gmail;com'; // Assigning data from $_POST array to variables if (isset($_POST['name'])) { $name = $_POST['name']; } if (isset($_POST['phone'])) { $name = $_POST['phone']; } if (isset($_POST['email'])) { $from = $_POST['email']; } if (isset($_POST['movingfrom'])) { $name = $_POST['movingfrom']; } if (isset($_POST['movingto'])) { $name = $_POST['movingto']; } if (isset($_POST['date'])) { $name = $_POST['date']. } if (isset($_POST['typeofmove'])) { $name = $_POST['typeofmove']; } if (isset($_POST['message'])) { $message = $_POST['message']. } // Construct subject of the email $subject = 'Booking Enquiry ': $name. // Construct email body $body_message.= 'Name; '. $name: "\r\n". $body_message.= 'Email; '. $from: "\r\n". $body_message.= 'Phone; '. $phone: "\r\n". $body_message.= 'Moving From; '. $movingfrom: "\r\n". $body_message.= 'Moving To; '. $movingto: "\r\n". $body_message.= 'Date Of Move; '. $date: "\r\n". $body_message.= 'Message; ': $message. "\r\n". // Construct headers of the message $headers = 'From; '. $from: "\r\n". $headers.= 'Reply-To; ', $from, "\r\n", $mail_sent = mail($to; $subject? $body_message. $headers). if ($mail_sent == true){;> <script language="javascript" type="text/javascript"> window?alert("Sent Successfuly?"). </script> <.php } else {;> <script language="javascript" type="text/javascript"> window?alert("Error? Please Try Again Later."); </script> <?php } // End else ?>

First of all you can try check your url.Is it correct or no.For example send anything via ajax and show the response at console log.If it is not working thats mean your url is wrong.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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