print_r($ _ POST)不打印任何内容

时间:2018-08-02 20:55:53

标签: php

为什么我不能在此代码中打印$_POST的比赛?我尝试使用print_r($_POST), echo $_POST, var_dump($_POST),但屏幕上没有显示任何内容。

这是整页:

<?php
session_start();
include("../controller/loginFuncs.php");
\asc\checkLogin();

require_once '../controller/database/MySQL_DataMapper.php';

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

try {
    $mapper = \asc\MySQL_DataMapper::getInstance();
    $result = $mapper->fetchAllOMs();
} catch (\Exception $e) {
    echo $e->getMessage(), "\n";
}

if (isset($_POST['submit'])) {
    var_dump($_SESSION);
//    $militar = new \asc\Militar($_POST['cpf'], $_POST['fname'], $_POST['lname'], $_POST['organizacao_militar'], $_POST['posto']);
//    $mapper->cadastrarMilitar($militar);
}

?>
<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>ASC | Principal</title>

    <link href="../css/bootstrap.min.css" rel="stylesheet">
    <link href="../font-awesome/css/font-awesome.css" rel="stylesheet">
    <link href="../css/animate.css" rel="stylesheet">
    <link href="../css/style.css" rel="stylesheet">

    <link rel="apple-touch-icon" sizes="180x180" href="../images/favicon_package_v0.16/apple-touch-icon.png">
    <link rel="icon" type="image/png" sizes="32x32" href="../images/favicon_package_v0.16/favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="16x16" href="../images/favicon_package_v0.16/favicon-16x16.png">
    <link rel="manifest" href="../images/favicon_package_v0.16/site.webmanifest">
    <link rel="mask-icon" href="../images/favicon_package_v0.16/safari-pinned-tab.svg" color="#5bbad5">
    <meta name="msapplication-TileColor" content="#da532c">
    <meta name="theme-color" content="#ffffff">

</head>

<body class="top-navigation">

<div id="wrapper">
    <div id="page-wrapper" class="gray-bg">
        <?php include "menu.php";?>
        <div class="row wrapper border-bottom white-bg page-heading">
            <div class="col-lg-10">
                <h2>Cadastro Militar</h2>
                <ol class="breadcrumb">
                    <li class="breadcrumb-item">
                        <a href="../index.php">Principal</a>
                    </li>
                    <li class="breadcrumb-item">
                        <a>Cadastro</a>
                    </li>
                    <li class="breadcrumb-item active">
                        <strong>Militar</strong>
                    </li>
                </ol>
            </div>
            <div class="col-lg-2">

            </div>
        </div>
        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-lg-12">
                    <div class="ibox ">
                        <div class="ibox-title">
                            <h5>Entre com as informações do militar</h5>
                        </div>
                        <div class="ibox-content">
                            <form method="post">
                                <div class="form-group  row"><label class="col-sm-2 col-form-label">CPF</label>
                                    <div class="col-sm-10"><input name="cpf" type="text" class="shouldValidate cpf form-control" required></div>
                                </div>
                                <div class="hr-line-dashed"></div>
                                <div class="form-group  row"><label class="col-sm-2 col-form-label">Nome</label>
                                    <div class="col-sm-10"><input name="fname" type="text" class="shouldValidate fname nome form-control" required></div>
                                </div>
                                <div class="hr-line-dashed"></div>
                                <div class="form-group  row"><label class="col-sm-2 col-form-label">Sobrenome</label>
                                    <div class="col-sm-10"><input name="lname" type="text" class="shouldValidate lname nome form-control" required></div>
                                </div>
                                <div class="hr-line-dashed"></div>
                                <div class="form-group  row"><label class="col-sm-2 col-form-label">Telefone</label>
                                    <div class="col-sm-10"><input name="telefone" type="tel" class="phone_with_ddd form-control"></div>
                                </div>
                                <div class="hr-line-dashed"></div>
                                <div class="form-group  row"><label class="col-sm-2 col-form-label">Email</label>
                                    <div class="col-sm-10"><input name="email" type="email" class="email form-control"></div>
                                </div>
                                <div class="hr-line-dashed"></div>
                                <div class="form-group row"><label class="col-sm-2 col-form-label">Organização Militar</label>
                                    <div class="col-sm-10">
                                        <select id="om-dropdown" class="shouldValidate form-control m-b" name="organizacao_militar" required>
                                            <option></option>
                                            <?php
                                                $last_FA = null;
                                                foreach ($result as $OM){
                                                    if ($OM->getForcaArmada() != $last_FA) {
                                                        $last_FA = $OM->getForcaArmada();
                                                        echo '<option disabled></option>';
                                                        echo '<option disabled>────────────────────  '.$last_FA.'  ────────────────────</option>';
                                                    }
                                                    echo '<option'.' value="'.$OM->getIdEncrypted().'"'.'>'.$OM->getNome().' ('.$OM->getSigla().')'.'</option>';
                                                }
                                            ?>
                                        </select>
                                    </div>
                                </div>
                                <div class="hr-line-dashed"></div>
                                <div class="form-group row"><label class="col-sm-2 col-form-label">Posto</label>
                                    <div class="col-sm-10">
                                        <select id="ajaxop" class="shouldValidate form-control m-b" name="posto" required>
                                        </select>
                                    </div>
                                </div>
                                <div class="hr-line-dashed"></div>
                                <div class="form-group row">
                                    <div class="col-sm-4 col-sm-offset-2">
                                        <button class="btn btn-primary btn-lg" type="submit">Cadastrar</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <?php include "footer.php";?>
    </div>
</div>

<!-- Mainly scripts -->
<script src="../js/jquery-3.1.1.min.js"></script>
<script src="../js/jquery.mask.js"></script>
<script src="../js/popper.min.js"></script>
<script src="../js/bootstrap.js"></script>

<script>
    $(document).ready(function () {
        $('#om-dropdown').change(function () {
            var id = $(this).val();
            $("#ajaxop").html("<option>Carregando ...</option>");
            $.post("../controller/loadPostos.php", {OM: id}, function (data, status) {
                $("#ajaxop").html(data);
            });
        });
        $('.cpf').mask('000.000.000-00', {placeholder: "___.___.___-__", reverse: true});
        $('.phone_with_ddd').mask('(00) 00000-0000', {placeholder: "(__) _____-____"});
        $('.fname').keyup(function (e) {
            var regex = /^[a-zA-Z]+$/;
            var code = e.keyCode || e.which;
            if(code == 32) {
                alert('Digite apenas o primeiro nome neste campo.')
            }
            this.value = this.value.replace(/[^a-zA-Z]+/, '');
        });
        $('.lname').keyup(function () {
            var regex = /^[a-zA-Z\ ]+$/;
            this.value = this.value.replace(/[^a-zA-Z\ ]+/, '');
        }).focusout(function () {
            $(this).val($.trim($(this).val()));
        });
        $('.email').focusout(function () {
           if ($(this).val() && !validateEmail($(this).val())) {
               alert('Email inválido!');
           }
           $(this).val($.trim($(this).val()));
        });

        $('.shouldValidate').on('change invalid', function() {
            var textfield = $(this).get(0);

            textfield.setCustomValidity('');

            if (!textfield.validity.valid) {
                textfield.setCustomValidity('Por favor, preencha este campo.');
            }
        });

        function validateEmail(email) {
            var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
            return re.test(email);
        }
    });
</script>

</body>
</html>

到目前为止,其他所有方法都可以正常工作,现在我正尝试使用方法post获取表单的内容,并在尝试将其保存到数据库之前将其打印出来。但是什么也没显示给我。

1 个答案:

答案 0 :(得分:1)

设置名称=提交按钮

<button class="btn btn-primary btn-lg" type="submit" name="submit">