English 中文(简体)
网址和jQuery接触表中的无端 lo错误
原标题:Endless loop error in php and jQuery contact form

Arrg。

我可以发现这种接触形式中的无休止的漏洞。 表格提交后,“比克”无休止地印刷。 我失踪了什么? 错误是没有的,还是错? (在工作档案中,通过<代码><script category=“text/javascript” src=“contact.js”></script>)

增 编

<?php 
if(isset($_POST[ submitted ])) {
if(trim($_POST[ checking ]) !==   ) {
$captchaError = true;
} else {

if(trim($_POST[ email ]) ===   )  {
$emailError =  Please enter a valid email address ;
$hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+.[A-Z]{2,4}$", trim($_POST[ email ]))) {
$emailError =  That s not a valid email address ;
$hasError = true;
} else {
$email = trim($_POST[ email ]);
}
}

if(!isset($hasError)) {

$emailTo =  to email ;
$subject =  site email ;
$body = "$email";
$headers =  From: webmail ;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
} ?>


<script type="text/javascript">

$(document).ready(function() {
    $( form#contactForm ).submit(function() {
        $( form#contactForm .error ).remove();
        var hasError = false;
        $( .requiredField ).each(function() {
            if($(this).hasClass( email )) {
                var emailReg = /^([w-.]+@([w-]+.)+[w-]{2,4})?$/;
                if(!emailReg.test(jQuery.trim($(this).val()))) {
                    var labelText = $(this).prev( label ).text();
                    $(this).parent().append( <span class="error">&nbsp;&nbsp;<i>invalid email</i></span> );

                    hasError = true;
                }
            }
        });
        if(!hasError) {
            $( #thanks ).fadeOut( normal , function() {
$(this).parent().append( <img src="../loading-small.gif" alt="Loading&hellip;" height="31" width="31" /> );

            });
            var formInput = $(this).serialize();
            $.post($(this).attr( action ),formInput, function(data){
                $( form#contactForm ).slideUp("fast", function() {                 
                    $(this).before( <p class="thanks">&nbsp;<strong>增 编!</strong> );
                    $(".thanks").delay(3000).fadeOut();
                });
            });
        }

        return false;

    });
});

</script>


<?php if(isset($emailSent) && $emailSent == true) { ?>

<div class="thanks"></div>

<?php } else { ?>

<form action="http://mysite.com" id="contactForm" method="post">

Sign up for email notification <input type="text" name="email" size="30" id="email" value="<?php if(isset($_POST[ email ]))  echo $_POST[ email ];?>" class="requiredField email" />

<?php if($emailError !=   ) { ?><span class="error"><?=$emailError;?></span><?php } ?>

<input type="hidden" name="submitted" id="submitted" value="true" />
<button type="submit">Send</form>

<?php } ?>
最佳回答

我对你的代码做了一些改动,然后用我的当地机器进行工作,看看这是否对你有用。

 <?php 
 if(isset($_POST[ submitted ])) {
    if(trim($_POST[ checking ]) !==   ) {
        $captchaError = true;
    }else{
        if(trim($_POST[ email ]) ===   )  {
            $emailError =  Please enter a valid email address ;
            $hasError = true;
        } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+.[A-Z]{2,4}$", trim($_POST[ email ]))) {
            $emailError =  That s not a valid email address ;
            $hasError = true;
        } else {
            $email = trim($_POST[ email ]);
        }
    }

    if(!isset($hasError)) {
        $emailTo =  to email ;
        $subject =  site email ;
        $body = "$email";
        $headers =  From: webmail ;
        mail($emailTo, $subject, $body, $headers);
        $emailSent = true;
    }
 } 
 ?>
 <html>
    <head>
        <title></title>
        <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
        <script type="text/javascript" src="js/jquery-ui.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $( form#contactForm ).submit(function() {
                $( .error ).remove(); //remove the existing error messages before we submit
                var hasError = false;
                //lets go through all the required feilds
                $( .requiredField ).each(function() {
                    //check to see if we are processing email
                    if($(this).hasClass( email )) {
                        var emailReg = /^([w-.]+@([w-]+.)+[w-]{2,4})?$/;
                        if(!emailReg.test(jQuery.trim($(this).val()))) {
                           // var labelText = $(this).prev( label ).text(); //this line seem useless
                            $(this).parent().append( <span class="error">&nbsp;&nbsp;<i>invalid email</i></span> ); // supply eror message
                            hasError = true; 
                        }
                    }
                });
                if(!hasError) {
                    $( #thanks ).fadeOut( normal , function() {
                        $(this).parent().append( <img src="../loading-small.gif" alt="Loading&hellip;" height="31" width="31" /> );
                    });
                    var formInput = $(this).serialize();
                    $.post($(this).attr( action ),formInput, function(data){
                        $( form#contactForm ).slideUp("fast", function() {                 
                            $(this).before( <p class="thanks">&nbsp;<strong>Thanks!</strong> );
                            $(".thanks").delay(3000).fadeOut();
                        });
                    });
                }
                return false;
            });
        });

    </script>
 </head>
 <body>



 <?php if(isset($emailSent) && $emailSent == true) { ?>

 <div class="thanks"></div>

 <?php } else { ?>

 <form action="<?php echo $_SERVER[ PHP_SELF ]; ?>" id="contactForm" method="post">

 Sign up for email notification <input type="text" name="email" size="30" id="email" value="<?php if(isset($_POST[ email ]))  echo $_POST[ email ];?>" class="requiredField email" />

 <?php if($emailError !=   ) { ?><span class="error"><?=$emailError;?></span><?php } ?>

 <input type="hidden" name="submitted" id="submitted" value="true" />
 <button type="submit">Send</form>

 <?php } ?>
    </body>
 </html>
问题回答

它希望你在具备现有要素(四)的同时,再尝试增加一个要素(<p等级=“thanks”)。 您能否缩小其中的界限? 另外,还有<代码>$(“#thanks”)。 fadeOut ,但t似乎没有任何内容,其编号为<>id。

我建议更仔细地通过该守则。 我看不到一种无休止的 lo,但如果出于某种原因,这种功能一再被启动,就会出现同样的症状。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签