Jump to content

Ezybusy

New Members
  • Posts

    4
  • Joined

  • Last visited

Everything posted by Ezybusy

  1. Thank you very much for your time. I will look through your solution and try to figure it out. In case it does not work, I will get rid of the Ajax processing, then use pure php to process my form.
  2. @gizmola Thank you for you reply. I tried your suggestion, but i could not find out the issue. However, i just found a file (main.js) among the js file I used. It contains the following Ajax code. Do you think this handles the form submit event ? If yes, could you pls help me add the redirect to it ? /*----------- 08. Ajax Contact Form ----------*/ var form = '.ajax-contact'; var invalidCls = 'is-invalid'; var $email = '[name="email"]'; var $validation = '[name="name"],[name="email"],[name="number"],[name="subject"],[name="callchoice"],[name="message"]'; // Must be use (,) without any space var formMessages = $(form).find('.form-messages'); function sendContact() { var formData = $(form).serialize(); var valid; valid = validateContact(); if (valid) { jQuery.ajax({ url: $(form).attr('action'), data: formData, type: "POST" }) .done(function (response) { // Make sure that the formMessages div has the 'success' class. formMessages.removeClass('error'); formMessages.addClass('success'); // Set the message text. formMessages.text(response); // Clear the form. $(form + ' input:not([type="submit"]),' + form + ' textarea').val(''); }) .fail(function (data) { // Make sure that the formMessages div has the 'error' class. formMessages.removeClass('success'); formMessages.addClass('error'); // Set the message text. if (data.responseText !== '') { formMessages.html(data.responseText); } else { formMessages.html('Oops! An error occured and your message could not be sent.'); } }); }; };
  3. I am sorry. Below is my code I am trying to add a redirect option to my mail sending code, but it seems not to work. Pls, can someone help me ? My form is as follows: <!doctype html> <html class="no-js" lang="fr"> <head> <body> <form action="mailer.php" class="form-style5 ajax-contact"> <div class="form-group"><input type="text" name="name" id="name" placeholder="Name"></div> <div class="form-group"><input type="text" name="email" id="email" placeholder="e-mail"></div> <div class="form-group"><input type="text" name="number" id="number" placeholder="Number"></div> <div class="form-group"> <select name="subject" id="subject"><option hidden disabled>Choose a subject</option> <option selected value="Pre-selected value">Subject 1</option> </select> </div> <button type="submit" class="vs-btn">Submit</button> <p class="form-messages"><span class="sr-only">For message will display here</span></p> </form> </body> </html> The code contained in the file mailer.php is below. <?php // Only process POST reqeusts. if ($_SERVER["REQUEST_METHOD"] == "POST") { // Get the form fields and remove whitespace. $name = strip_tags(trim($_POST["name"])); $name = str_replace(array("\r","\n"),array(" "," "),$name); $email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL); $number = trim($_POST["number"]); $subject = trim($_POST["subject"]); // Check that data was sent to the mailer. if ( empty($name) OR empty($subject) OR empty($number) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) { // Set a 400 (bad request) response code and exit. http_response_code(400); echo "Plese fill the form."; exit; } // Set the recipient email address. $recipient = "[email protected]"; // Set the email subject. $subject = "New registration - $subject"; // Build the email headers. $email_headers = "From: $name <$email>\r\n"; $email_headers .= "MIME-Version: 1.0\r\n"; $email_headers .= "Content-type: text/html; charset=ISO-8859-1\r\n"; // Build the email content. $email_content = '<html><body>'; $email_content .= '<table rules="all" style="border-color: #333333;" cellpadding="15px";>'; $email_content = "<tr style='font-size:14px; margin-bottom:5px;'><td><strong>Name:</strong></td><td> $name</td></tr>"; $email_content .= "<tr style='font-size:14px; margin-bottom:5px;'><td><strong>Subject:</strong></td><td> $subject</td></tr>"; $email_content .= "<tr style='font-size:14px; margin-bottom:5px;'><td><strong>E-mail:</strong></td><td> $email</td></tr>"; $email_content .= "<tr style='font-size:14px; margin-bottom:5px;'><td><strong>Phone:</strong></td><td> $number</td></tr>"; $email_content .= "</table>"; $email_content .= "</body></html>"; // Send the email. if (mail($recipient, $subject, $email_content, $email_headers)) { // Set a 200 (okay) response code. http_response_code(200); echo "Thank you for filling in the form. Your registration has been sent."; } else { // Set a 500 (internal server error) response code. http_response_code(500); echo "Oops! A problem occurred and we were unable to submit your registration."; } } else { // Not a POST request, set a 403 (forbidden) response code. http_response_code(403); echo "There was a problem with your registration, please try again."; } ?> At the moment, everything works fine, and it displays a success message to the user after he submits the form. But I want to take the users to a different page where I can propose another service to them. So, after submitting the form, they should be redirected to that new page register_success.php . I tried the code below, but it rather outputs the content of register_success.php on the under the form after clicking the submit button : // Send the email. if (mail($recipient, $subject, $email_content, $email_headers)) { header("Location: register_success.php");
  4. Hello everyone, I am trying to add a redirect option to my mail sending code, but it seems not to work. Pls, can someone help me ? I tried to add a redirect using header("Location: thanks.php"); but it does not work. Form and mail sending files are attached below https://drive.google.com/file/d/1uA_wt8Ztofs0RHLZpensO8XjqeQuoDta/view?usp=sharing
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.