質問

I have some trouble cleaning and making my contact form working.

I'm using a template which had a captcha validation and I don't want it. There was also a "website input that I delete.

I'm a newbie in php so I don't really know what I have to remove and I don't want to start a new php/js files

My contact-send.php file is in a php folder. So I assume the action call in the html is good.

I have two other files in there ( captcha_page.php and image.php but I won't use here, will delete it, so I don't post code )

<form class="contact-form" method="post" action="php/contact-send.php">

<p class="input-block">
    <input type="text" name="name" id="name" placeholder="Name *" />
 </p>

 <p class="input-block">
    <input type="email" name="email" id="email" placeholder="Email *" />
 </p>

 <p class="input-block">
    <textarea name="message" id="message" placeholder="Message *"></textarea>   
 </p>


 <p class="input-block">
    <button class="button turquoise submit" type="submit" id="submit"><i class="icon-paper-plane"></i></button>
 </p>

 </form><!--/ .contact-form-->


<?php

if (isset($_REQUEST['action'])) {

    if ($_REQUEST['action'] == "contact_form_request") {

        $ourMail = "xxx.xxxx@gmail.com";

        $required_fields = array("name", "email", "message");
        $pre_messagebody_info = "";

        $errors = array();
        $data = array();

        parse_str($_REQUEST['values'], $data);

        //check for required and assemble message

        if (!empty($data)) {
            foreach ($data as $key => $value) {
                $name = strtolower(trim($key));
                if (in_array($name, $required_fields)) {
                    if (empty($value)) {

                        if ($name == "name") {
                            $errors[$name] = "Please enter your Name before sending the message";
                        }

                        if ($name == "message") {
                            $errors[$name] = "Please enter your message ";
                        }

                        if ($name == "email") {
                            if (!isValidEmail($value)) {
                                $errors[$name] = "Please enter correct Email address";
                            }           
                        }

                    }
                }
            }
        }

        session_start();
        $verify = $_SESSION['verify'];
        if ($verify != md5($data['verify'])) {
            $errors["verify"] = "Please enter correctly captcha";
        }

        $result = array (
            "is_errors" => 0,
            "info" => ""
        );

        if (!empty($errors)) {
            $result['is_errors'] = 1;
            $result['info'] = $errors;
            echo json_encode($result);
            exit;
        }

        $pre_messagebody_info .= "<strong>Name</strong>" . ": " . $data['name'] . "<br />";
        $pre_messagebody_info .= "<strong>E-mail</strong>" . ": " . $data['email'] . "<br />";
        $pre_messagebody_info .= "<strong>Website</strong>" . ": " . $data['website'] . "<br />";

        $headers = 'MIME-Version: 1.0' . "\r\n";
        $headers.= 'Content-type: text/html; charset=UTF-8' . "\r\n";
        $headers.= "From: " . $data['email'] . "\r\n";

        $after_message = "\r\n<br />--------------------------------------------------------------------------------------------------\r\n<br /> This mail was sent via contact form";

        if (mail($ourMail, "Email from contact form", $pre_messagebody_info .="<strong>Message</strong>" . ": " . nl2br($data['message']) . $after_message, $headers)) {
            $result["info"] = "success";
        } else {
            $result["info"] = "server_fail";
        }

        echo json_encode($result);
        exit;
    }
}

function isValidEmail($email) {
    return filter_var($email, FILTER_VALIDATE_EMAIL);
}

?>


    if ($('.contact-form').length) {

        var $form = $('.contact-form'),
            $loader = '<span>Loader...</span>';
            $form.append('<div class="hide contact-form-responce" />');

        $form.each(function () {

            var $this = $(this), 
                $response = $('.contact-form-responce', $this).append('<p></p>');

            $this.submit(function () {

                $response.find('p').html($loader);

                var data = {
                    action: "contact_form_request",
                    values: $this.serialize()
                };

                //send data to server
                $.post("php/contact-send.php", data, function (response) {

                    $('.wrong-data', $this).removeClass("wrong-data");
                    $response.find('span').remove();    

                    response = $.parseJSON(response);

                    if (response.is_errors) {

                        var p = $response.find('p');

                        p.removeClass().addClass("error");
                        $.each(response.info, function (input_name, input_label) {
                            $("[name=" + input_name + "]", $this).addClass("wrong-data");
                            p.append(input_label + '</br>');
                        });
                        $response.show(300);
                    } else {
                        $response.find('p').removeClass().addClass('success');
                        if (response.info === 'success') {
                            $response.find('p').append('Your email has been sent!');
                            $this.find('input, textarea, select').val('').attr('checked', false);
                            $response.show(300).delay(2500).hide(400);
                        }

                        if (response.info === 'server_fail') {
                            $response.find('p').append('Server failed. Send later!');
                            $response.show(300);
                        }
                    }

                    // Scroll to bottom of the form to show respond message
                    var bottomPosition = $response.offset().top - 50;

                    if ($(document).scrollTop() < bottomPosition) {
                        $('html, body').animate({ scrollTop : bottomPosition });
                    }


                });

                return false;

            });
        });

    }

sorry, html, php and js are together, didn't manage to make something better...

thanks a lot guys !!!

remi

役に立ちましたか?

解決

remove these lines :

   $verify = $_SESSION['verify'];
    if ($verify != md5($data['verify'])) {
        $errors["verify"] = "Please enter correctly captcha";
    }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top