0

I have this form and have issues with my $_POST data not coming through:

Form:

<form action="" id="contact-form" method="post">

           <input id="nombre" size="16" type="text" placeholder="Nombre">

           <input id="email" size="16" type="text" placeholder="Email">

           <textarea id="texto"></textarea>

           <input type="submit" value="Enviar">

PHP:

<?php

 if(!empty($_POST) {

 echo "YES";

 } else {

 echo "NO";

 }

?>

It always echoes "NO" when I complete and submit all the fields.

Castiblanco
  • 1,200
  • 4
  • 13
  • 32

6 Answers6

3

You missed the name attribute of the input fields. Change your html and add them:

<form action="" id="contact-form" method="post">
    <input id="nombre" name="nombre" size="16" type="text" placeholder="Nombre">
    <input id="email" name="email" size="16" type="text" placeholder="Email">
    <textarea id="texto" name="texto"></textarea>
    <input type="submit" value="Enviar">

Note that the id attribute is not required. You can omit it if you don't need it for other purposes like using it in a stylesheet or in javascript. For simply sending the form just the name attribute is required

hek2mgl
  • 152,036
  • 28
  • 249
  • 266
  • Ohh my goodness .. it's so simple and right in front of my eyes ... I'm a newby as you should realize.. hehe .. thanks very much . .everyone for helping me.. :) – user1925226 Apr 10 '13 at 21:48
  • Level complete. Go forward to the next error! :) Happy coding! :) – hek2mgl Apr 10 '13 at 21:49
1

if you want a specific field, try:

if(isset($_POST['field']{0})){

If you want to check for multiple fields POST, try:

if(count($_POST)>0){
Protomen
  • 9,471
  • 9
  • 57
  • 124
  • always an idiot who only come here to earn `score` and why the other negative responses. The only reason would be to help and share, and not be up with Importing `score`. – Protomen Apr 10 '13 at 22:17
  • Sorry Guilherme ... I can't do anything about it... I have no voting rights yet ... but it's incredible that there's so stupid people in a website that is suposed to be used to help other people rather than take them down ... your answer is valid too .. I've just tried it... – user1925226 Apr 10 '13 at 23:28
  • Thanks for responding to my comment. I really do not care about the votes, but not to worry it is not your responsibility. Good luck. – Protomen Apr 11 '13 at 13:14
0

Your input should have the name attribute set, which sets them in $_POST array. id is ignored in posting forms!

<input id="nombre" size="16" type="text" placeholder="Nombre" name="nombre">

and you will get it in $_POST['nombre']

p91paul
  • 1,104
  • 10
  • 26
0

This is an alternative solution ,if you add "name" attribute to your inputs , it should work:

 if (count($_POST) == 0)  {

         echo "YES";
    }
  else {

         echo "NO";

       }
Charaf JRA
  • 8,249
  • 1
  • 34
  • 44
-1

You need to specify a variable, so $_POST['email'] for example. For all of the fields try;

if(!empty($_POST['Nombre']) && !empty( $_POST['email']) && !empty ( $_POST['texto'])) { ...

Sorry I'm on a mobile device, such a pain to get all the spelling correct.

Protomen
  • 9,471
  • 9
  • 57
  • 124
Alex
  • 493
  • 1
  • 6
  • 11
-1
if (empty($_POST['qty'])) {
    echo "<script>alert('inputan Quality tidak boleh kosong');history.go(-1);</script>";
} 
else {
    ...
}

so no validation error, here I use array

Adeel
  • 2,901
  • 7
  • 24
  • 34