Jump to content

Chrisj

Members
  • Posts

    531
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Chrisj

  1. Thanks for your reply. But, I'm not clear on what you're asking for. Is it this?: <?php session_start(); $code=rand(1000,9999); $_SESSION["code"]=$code; $im = imagecreatetruecolor(80, 24); $bg = imagecolorallocate($im, 177, 78, 78); $fg = imagecolorallocate($im, 255, 255, 255); imagefill($im, 0, 0, $bg); imagestring($im, 5, 24, 3, $code, $fg); header("Cache-Control: no-cache, must-revalidate"); header('Content-type: image/png'); imagepng($im); imagedestroy($im); ?>
  2. I merged this code from a captcha script: <?php session_start(); if(isset($_POST["captcha"])&&$_POST["captcha"]!=""&&$_SESSION["code"]==$_POST["captcha"]) { echo "Correct Code Entered"; //Do your stuff } else { die("Wrong Code Entered"); } ?> with a working Contact Form script code: <?php $data = json_decode(file_get_contents("php://input")); $name = trim($data->name); $name = str_replace(array("\r", "\n"), array(" ", " "), $name); $email = filter_var(trim($data->email), FILTER_SANITIZE_EMAIL); $message = trim($data->message); // Check that data was sent. if (empty($name) || empty($message) || !filter_var($email, FILTER_VALIDATE_EMAIL)) { echo "One or more invalid entries. Please try again."; exit; } $to = "support@...com"; $from = "From: contact-form@...com". "\r\n"; $body = "A message has been sent via the website contact form.\n\n"; $body .= "Name: $name\n"; $body .= "Email: $email\n\n"; $body .= "Message:\n$message\n"; if (mail($to, 'Customer Inquiry', $body)){ echo "Thank You. Your Message Has Been Sent."; } else { echo "An error has occurred and your message could not be sent."; } ?> to get this: <?php session_start(); $data = json_decode(file_get_contents("php://input")); $name = trim($data->name); $name = str_replace(array("\r", "\n"), array(" ", " "), $name); $email = filter_var(trim($data->email), FILTER_SANITIZE_EMAIL); $message = trim($data->message); // Check that data was sent. if (empty($name) || empty($message) || !filter_var($email, FILTER_VALIDATE_EMAIL)) { echo "One or more invalid entries. Please try again."; exit; } if(isset($_POST["captcha"])&&$_POST["captcha"]!=""&&$_SESSION["code"]==$_POST["captcha"]) { echo "Correct Code Entered"; //Do your stuff } else { die("Wrong Code Entered"); } $to = "support@...com"; $from = "From: contact-form@...com". "\r\n"; $body = "A message has been sent via the website contact form.\n\n"; $body .= "Name: $name\n"; $body .= "Email: $email\n\n"; $body .= "Message:\n$message\n"; if (mail($to, 'Customer Inquiry', $body)){ echo "Thank You. Your Message Has Been Sent."; } else { echo "An error has occurred and your message could not be sent."; } ?> but after I tested/completed the Form, including entering the correct Captcha code, I see the message "Wrong Code Entered", and of course the Contact Form info does not send. I added this (after the 'session start' line): var_dump($_SESSION); and ran the Form, and I see this: array(2) { ["security_code"]=> string(6) "9569qb" ["code"]=> int(6133) } Wrong Code Entered Any guidance with integrating captcha script successfuly will be appreciated.
  3. I have this Contact Form, that I'm trying to add a captcha element to it. The captcha script html part is this: <td> Enter Image Text<input name="captcha" type="text"><img src="captcha.php" /> </td> And it looks like (see attached image) How can I style this, and also put some space between the text, the field box, and the numbers box, horizontally? I look forward to some suggestions. Much thanks.
  4. Thanks for your replies. Any additional help will be appreciated.
  5. Thanks for your replies. This is not code that I wrote. Someone provided it to me and it seems like it's close to working. I'm not familiar with "superglobal $_PRINT". And I'm not clear on "put the contact data into the e-mail content", doesn't the Contact Form user enter the content into the Form fields? And additional guidance/examples, would be appreciated
  6. When 'submit' is selected in this Contact Form, the 'message' field info is the only thing that sends/arrives. Someone suggested it may have to do with the 'mail command', but any help with getting the 'name' and 'email' field info to send will be appreciated. <?php $data = json_decode(file_get_contents("php://input")); $name = trim($data->name); $name = str_replace(array("\r", "\n"), array(" ", " "), $name); $email = filter_var(trim($data->email), FILTER_SANITIZE_EMAIL); $message = trim($data->message); if (empty($name) || empty($message) || !filter_var($email, FILTER_VALIDATE_EMAIL)) { echo "One or more invalid entries. Please try again."; exit; } $to = "support@...com"; $from = "From: contact-form@...com". "\r\n"; if (mail($to, "Customer Inquiry", $message)) { echo "Thank You. Your message has been sent."; } else { echo "An error has occurred and your message could not be sent."; } ?> Here's more code: <form id="ajax-contact" method="post"> <table class="table10"> <tr> <td> <label for="name">Your Name:</label> <input id="contact-name" type="text" name="name" required> </td> </tr> </tr> <tr> <td> <label for="email">Your Email Address:</label> <input id="contact-email" type="email" name="email" required> </td> </tr> <tr> <td> <label for="message">Message:</label> <textarea id="contact-message" type="text" name="message" required></textarea> </td> </tr> <tr> <td> <button type="submit">Send</button> </td> </table> </form> <div id="form-response"></div> <script> $(function () { var form = $("#ajax-contact"); form[0].reset(); form.submit(function (event) { event.preventDefault(); var data = { "name": $("#contact-name").val(), "email": $("#contact-email").val(), "message": $("#contact-message").val() }; $.ajax({ url: "../contact_form_handle.php", data: JSON.stringify(data), contentType: "application/json; charset=utf-8", dataType: "text", type: "POST"}) .done(function (response) { $("#form-response").text(response); form[0].reset(); }) .fail(function (data) { if (data.responseText.length) { $("#form-response").text(data.responseText); } else { $("#form-response").text("An error has occurred and your message could not be sent."); } }) }); }); </script>
×
×
  • 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.