首页 > 解决方案 > HTML 表单验证和安全性

问题描述

我创建了一个带有验证和 php 验证的基本表单。我还在表单中添加了重新验证码,因为我收到了很多不适当的垃圾邮件,并且由于某种原因,在上次更新了表单上的安全性之后。我仍然收到不适当的垃圾邮件,因此我错过了可能通过表格发送给我的重要电子邮件。

我试过搜索互联网和在线教程,但他们只是告诉我我已经做了什么。我的代码如下:

HTML:

<div class="contact">

        <div class="container">
            <h2>Contact US</h2>
        <div class="contact-form">

            <div class="col-md-8 contact-grid">
                <form id="test" action="form-process.php" method="POST">
                    <input name="name" type="text" placeholder="Name" onfocus="this.value='';" onblur="if (this.value == '') {this.value ='name';}" required>
                    <br>
                    <input name="email" type="text" placeholder="Email" onfocus="this.value='';" onblur="if (this.value == '') {this.value ='email';}" required>
                    <br>
                    <select id="contact" name="dropdown" onchange="handleOption(this)" required>
                        <option value="" disabled selected>Crew/Gang</option>
                        <option value="NC Maphia">NC Maphia</option>
                        <option value="deadeye/index">Dead Eye</option>
                    </select><br>
                    <select id="contact" name="dropdown2" required>
                        <option value="" disabled selected>Game</option>
                        <option value="Grand Theft Auto V">Grand Theft Auto V</option>
                        <option value="Red Dead Redemption II">Red Dead Redemption II</option>
                    </select><br>
                    <select id="contact" name="dropdown3" required>
                        <option value="" disabled selected>Platform</option>
                        <option value="Xbox One">Xbox One</option>
                        <option value="PS4">PS4</option>
                    </select><br>
                    <select id="contact" name="dropdown4" required>
                        <option value="" disabled selected>Reason For Contacting Us</option>
                        <option value="Joining NC Maphia">Joining NC Maphia</option>
                        <option value="Recruitment Requirments">Recruitment Requirments</option>
                        <option value="Events">Events</option>
                        <option value="Report A Member">Report A Member</option>
                        <option value="Webmaster">Webmaster</option>
                        <option value="General Inquiry">General Inquiry</option>
                    </select><br>
                    <input name="subject" type="text" placeholder="Subject" onfocus="this.value='';" onblur="if (this.value == '') {this.value ='subject';}">
                    <br>
                    <textarea name="message" cols="77" rows="6" placeholder="Message" onfocus="this.value='';" onblur="if (this.value == '') {this.value = 'message';}" required></textarea>
                    <span class="msg-error error"></span>
                    <div id="recaptcha" class="g-recaptcha" data-sitekey="6Ler9H8UAAAAAElg86pX58oN-G2a125GwNoBY9X4"></div>
                    <div class="send">
                        <input type="submit" name="submit" value="Send" >
                    </div>
                </form>
            </div>
            <div class="col-md-4 contact-in">

                    <div class="address-more">
                    <h4>Address</h4>
                        <p>Maze Bank Tower,</p>
                        <p>Los Santos,</p>
                        <p>America </p>
                    </div>
                    <div class="address-more">
                    <h4>Chat With Us</h4>
                        <p>PSN: Kyle-The-Gunman9</p>
                        <p>PSN: NC_Maphia</p>
                        <p>Email:<a href="mailto:email@example.com"> email[at]example.com</a></p>
                    </div>

            </div>
            <div class="clearfix"> </div>
        </div>
    </div>
    <script type="text/javascript">
        function handleOption(elm) {
        if(elm.value == "deadeye/index") { // Check if Dead Eye was selected
            console.log("Dead Eye selected, redirecting");
            window.location = elm.value + ".html";
        }
    }
    $( '.send' ).click(function(){
        var $captcha = $( '#recaptcha' ),
        response = grecaptcha.getResponse();
    if (response.length === 0) {
        $( '.msg-error').text( "Oops You forgot to do the ReCaptcha!" );
    if( !$captcha.hasClass( "error" ) ){
        $captcha.addClass( "error" );
    }
} else {
    $( '.msg-error' ).text('');
    $captcha.removeClass( "error" );
    alert( 'Processing...' );
}
})
    </script>
    <div class="map">
            <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d37494223.23909492!2d103!3d55!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x453c569a896724fb%3A0x1409fdf86611f613!2sRussia!5e0!3m2!1sen!2sin!4v1415776049771"></iframe>
        </div>
</div>

我的 PHP 代码在 pastebin 上。你可以在下面查看

https://pastebin.com/0ngFXM8U

我想要我的联系表格,这样当它进行完整验证并且用户无法滥用表格时。如果这有意义

在此先感谢任何帮助。

标签: phphtml

解决方案


推荐阅读