Wijaya
Wijaya

Reputation: 65

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. 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.

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

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 :)

Upvotes: 1

Views: 59

Answers (4)

elbrant
elbrant

Reputation: 791

I suspect the issue is in the way you assigned your variable values: $nama =isset($_POST['name1']);. Simplify it as $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.

<?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;
?>

Upvotes: 0

Ashwin Pandey
Ashwin Pandey

Reputation: 125

    <?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. 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.

Upvotes: 1

Chris van der Gaag
Chris van der Gaag

Reputation: 47

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);
?>

Upvotes: 0

pr1nc3
pr1nc3

Reputation: 8338

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.

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.

Upvotes: 1

Related Questions