简体   繁体   English

FORM什么都不提交

[英]FORM don't submit anything

I have some php and html code, what I want to do is just catch the data from form and print it in one file. 我有一些php和html代码,我想做的就是从表单中捕获数据并将其打印在一个文件中。 But when I click submit there is no data. 但是,当我单击“提交”时,没有任何数据。

I've tried to break the code to be 2 part but there is no change. 我试图将代码分为2部分,但没有任何变化。

This is the code: 这是代码:

<section id="register" class="section-with-bg wow fadeInUp">
        <div class="container">
            <div class="section-header">
              <h2>Register</h2>
            </div>
            <div class="form">
                <div id="errormessage"></div>
                <form id="data" action="#" method="post" class="contactForm">
                    <div class="form-row">
                        <div class="form-group col-md-6">
                            <input type="text" name="name1" class="form-control" id="name1" placeholder="Nama Depan" />
                            <!--<div class="validation"></div>-->
                        </div>
                        <div class="form-group col-md-6">
                            <input type="text" name="email" class="form-control" id="email" placeholder="Email" />
                            <!--<div class="validation"></div>-->
                        </div>
                        <div class="form-group col-md-6">
                            <input type="text" class="form-control" name="pekerjaan" id="pekerjaan" placeholder="Pekerjaan" />
                            <!--<div class="validation"></div>-->
                        </div>
                        <div class="form-group col-md-6">
                            <input type="text" name="nip" class="form-control" id="nip" placeholder="NIP (Jika Anda Seorang ASN)"/>
                            <!--<div class="validation"></div>-->
                        </div>
                    </div>
                    <div class="form-row">
                        <div class="form-group col-md-6">
                            <input type="password" name="pwd" class="form-control" id="pwd" placeholder="Password" />
                            <!--<div class="validation"></div>-->
                        </div>
                        <div class="form-group col-md-6">
                            <input type="password" class="form-control" name="pwd2" id="pwd2" placeholder="Repeat Password" />
                            <!--<div class="validation"></div>-->
                        </div>
                    </div>
                    <div class="form-row">
                        <div class="form-group col-md-6">
                            <input type="text" name="tlp" class="form-control" id="tlp" placeholder="Telepon" />
                            <!--<div class="validation"></div>-->
                        </div>
                        <div class="form-group col-md-6">
                            <input type="text" name="hp" class="form-control" id="hp" placeholder="HP" />
                            <!--<div class="validation"></div>-->
                        </div>
                    </div>
                    <div class="form-group">
                        <textarea class="form-control" name="message" rows="5" placeholder="Alamat"></textarea>
                            <!--<div class="validation"></div>-->
                    </div>
                    <div class="text-center"><input type="submit" value="Submit" name ="submit" class="btn btn-primary" data-toggle="modal" data-target="#myModal"></div>
                </form>
            </div>
        </div>
    </section>

    <?php
      $nama =isset($_POST['name1']);
      $pekerjaan =isset($_POST['pekerjaan']);
      $nip =isset($_POST['nip']);
      $email =isset($_POST['email']);
      $pwd =isset($_POST['pwd']);
      $pwd2 =isset($_POST['pwd2']);
      $tlp =isset($_POST['tlp']);
      $hp =isset($_POST['hp']);
      $message =isset($_POST['message']);

      echo $nama;
      echo $pekerjaan;
      echo $nip;
      echo $email;
      echo $pwd;
      echo $pwd2;
      echo $tlp;
      echo $message;
    ?>

I try to make simple code with just 1 input and 1 submit button and it works 我尝试只用1个输入和1个提交按钮来制作简单的代码,并且可以正常工作

Update: Thank you guys for your help I already solved the problem I got some error in my JS code and now my code working :) 更新:谢谢大家的帮助我已经解决了这个问题,我的JS代码出现了一些错误,现在我的代码可以正常工作了:)

Your code returns "boolean" values because you assign boolean values to your variables: 您的代码返回“布尔”值,因为您为变量分配了布尔值:

$message =isset($_POST['message']); this line will assign true or false to the $message variable. 该行将为$message变量分配true或false。

If you want to check if the value is isset so you can print it then you have to do it like: 如果要检查该值是否已设置,以便可以打印它,则必须执行以下操作:

$message = isset($_POST['message'])? $message = $_POST['message']: $message = '';

This is just an example in 1 of your lines. 这只是您的一行中的一个示例。 The same logic applies to all your variables. 相同的逻辑适用于所有变量。

    <?php
if (isset($_POST['submit'])) {
      $nama =isset($_POST['name1']);
      $pekerjaan =isset($_POST['pekerjaan']);
      $nip =isset($_POST['nip']);
      $email =isset($_POST['email']);
      $pwd =isset($_POST['pwd']);
      $pwd2 =isset($_POST['pwd2']);
      $tlp =isset($_POST['tlp']);
      $hp =isset($_POST['hp']);
      $message =isset($_POST['message']);

      echo $nama;
      echo $pekerjaan;
      echo $nip;
      echo $email;
      echo $pwd;
      echo $pwd2;
      echo $tlp;
      echo $message;
}
    ?>

Replace this with your current php code. 将其替换为您当前的PHP代码。 You are not checking weather the form is submitted or not. 您不检查天气是否提交表单。 It can be done using an if statement where it checks if the submit button was clicked. 可以使用if语句在其中检查是否单击了提交按钮来完成此操作。

try adding this on top of your code 尝试将其添加到您的代码之上

<?php
  session_start();
  extract($_POST, EXTR_SKIP);
  extract($_GET, EXTR_SKIP);
  extract($_SESSION, EXTR_SKIP);
  extract($_FILES, EXTR_SKIP);
?>

I suspect the issue is in the way you assigned your variable values: $nama =isset($_POST['name1']); 我怀疑问题出在分配变量值的方式上: $nama =isset($_POST['name1']); . Simplify it as $nama = $_POST['name1']; 简化为$nama = $_POST['name1']; . Keep in mind that if your site visitor doesn't change (any of the) input fields, those inputs may show up with your placeholder= values. 请记住,如果您的网站访问者未更改(任何一个)输入字段,则这些输入可能会显示为您的placeholder=值。

<?php
  $nama = $_POST['name1'];
  $pekerjaan = $_POST['pekerjaan'];
  $nip = $_POST['nip'];
  $email = $_POST['email'];
  $pwd = $_POST['pwd'];
  $pwd2 = $_POST['pwd2'];
  $tlp = $_POST['tlp'];
  $hp = $_POST['hp'];
  $message = $_POST['message'];

  echo $nama;
  echo $pekerjaan;
  echo $nip;
  echo $email;
  echo $pwd;
  echo $pwd2;
  echo $tlp;
  echo $message;
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM