2

I've builded a WordPress theme based on Twitter Bootstrap 3.x. I've a mail form in modal box. When I click submit button, it returns 404 error page. I also checked for reserved names in $_POST and $_REQUEST variables.

What can be the reason?

<?php get_header(); ?>
<script src='https://www.google.com/recaptcha/api.js'></script>
<?php
$hasError = '';
$succMsg = '';
if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$bsvr_ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$bsvr_ip_address = $_SERVER['REMOTE_ADDR'];
}
if(isset($_POST['submit']) && !empty($_POST['submit'])):

if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])):

    $secret = 'key';
    $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
    $responseData = json_decode($verifyResponse);

    if (!empty($_POST['bsvr_name'])) {
        $bsvr_name = stripslashes(trim($_POST['bsvr_name']));
    } else {
        $hasError = "Lütfen adınızı giriniz.";
    }

    if (!empty($_POST['bsvr_email'])) {
        $bsvr_email = stripslashes(trim($_POST['bsvr_email']));
    } else if ( ! eregi( "^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['bsvr_email'] ) ) ) {
        $hasError = 'Geçersiz e-posta adresi girdiniz.';
    } else {
        $hasError = "Lütfen e-posta adresinizi giriniz.";
    }

    $bsvr_egitim = $_POST['bsvr_egitim'];

    if($responseData->success):

        $to = 'tomail';
        $subject = 'Title';
        $htmlContent = "
            <h1>Content</h1>
            <p><b>Name: </b>".$bsvr_name."</p>
            <p><b>E-Mail: </b>".$bsvr_email."</p>
            <p><b>Title: </b>".$bsvr_egitim."</p><br/><br/>
            <p><b>IP: </b>".$bsvr_ip_address."</p>
        ";
        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
        $headers .= 'From:'.$bsvr_name.' <'.$bsvr_email.'>' . "\r\n";

        @mail($to,$subject,$htmlContent,$headers);

        $succMsg = "Ok..";
        $bsvr_name = '';
        $bsvr_email = '';
        $bsvr_egitim = '';

    else :

        $hasError = "Bir hata oluştu, lütfen tekrar deneyiniz.";

    endif;

else :

    $hasError = "Bir hata oluştu, lütfen tekrar deneyiniz.";

endif;
else :

$hasError = '';
$succMsg = '';
$bsvr_name = '';
$bsvr_email = '';
$bsvr_egitim = '';  
endif;
?>

<!-- Modal -->
<div class="modal fade" id="basvuru" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">EĞİTİME BAŞVUR</h4>
        </div>
        <div class="modal-body">
            <form class="contactForm" id="egitimform" name="egitimform" method="post" action="<?php the_permalink(); ?>" enctype="multipart/form-data">
                <div class="form-group">
                    <label for="name" class="col-sm-3 control-label">Name</label>
                    <div class="col-sm-9">
                        <input type="text" class="form-control" name="bsvr_name" id="bsvr_name" placeholder="Name">
                    </div>
                </div>
                <div class="form-group">
                    <label for="bsvr_email" class="col-sm-3 control-label">E-Mail</label>
                    <div class="col-sm-9">
                        <input type="bsvr_email" class="form-control" name="bsvr_email" id="bsvr_email" placeholder="E-Mail">
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-9 col-sm-offset-3">
                        <div class="g-recaptcha" data-sitekey="key"></div>
                    </div>
                </div>
                <input type="hidden" name="bsvr_egitim" value="<?php the_title(); ?>">
            </form>
        </div>
        <div class="modal-footer">
            <input type="submit" name="submit" class="button" id="egitimsubmit" value="GÖNDER">
        </div>
    </div>
</div>
</div>
<script>
$('#egitimsubmit').on('click', function(e){
// We don't want this to act as a link so cancel the link action
e.preventDefault();

// Find form and submit it
$('#egitimform').submit();
});
</script>
1
  • 1
    Have you tried leaving the action="<?php the_permalink(); ?>" empty?
    – kaiser
    Jul 24, 2016 at 20:39

1 Answer 1

0

Only changed <div class="modal-dialog" role="document"> to <div class="modal-dialog" role="dialog">. And now it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.