Simple form not sending data via _POST

Wow, so this is awkward. This is supposed to be another boring web form. I have already done a lot, but for some reason this particular one does not want to cooperate. Did I miss something? I tried to figure this out for hours. I swear I tried to eliminate everything without luck.

Basically, I'm trying to send a PHP file via $ _POST. In the end I will use AJAX, but now I can’t even get a dumb POST. Therefore, when you click the "Submit" button, it goes to the correct page. But I get the error "Undefined Index (then points to the line that I call the variable $ _POST). I commented everything on the PHP side (signup1.php), so now all it does is var_dump($_POST); so I see the data and it doesn’t receive anything from _POST, the stupid thing is empty. I really think the problem is on the HTML side. I will definitely lay out my code. It has a ton of additional sections for styles and layouts. I am going to save all this there, just in case, this is the cause of the error, maybe one of you will find out.In addition, you may notice that I'm using th the bootstrap. Maybe it's something? I used to bootstrap forms earlier and it worked, but who knows.

 <form action="actions/signup1.php" method="post"> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="name">Name:</label> <input type="text" id="name" class="form-control" placeholder="John Smith"> </div> </div> <!-- end of name input column --> <div class="col-md-6"> <div class="form-group"> <label for="phone">Phone Number:</label> <input type="text" id="phone" class="form-control" placeholder="801-321-9876"> </div> </div> <!-- end of phone number input column --> </div> <!-- end of first .row of inputs --> <div class="row"> <div class="col-md-6 column-sm-12"> <div class="form-group"> <label for="email">Email Address:</label> <input type="text" id="email" class="form-control" placeholder=" johnsmith@me.com "> </div> </div> <!-- end of email address input column --> <div class="col-md-3 col-sm-6"> <div class="form-group"> <label for="city">City:</label> <select id="city" class="form-control"> <option>Las Vegas</option> <option>Salt Lake City</option> <option>I'll Choose a Default Later...</option> </select> </div> </div> <!-- end of city dropdown --> <div class="col-md-3 col-sm-6"> <div class="form-group"> <label for="type-of-phone">Type of Phone:</label> <select id="type-of-phone" class="form-control"> <option>iPhone</option> <option>Android</option> <option>Windows Phone</option> <option>Blackberry</option> <option>Other Cellphone</option> <option>Landline</option> </select> </div> </div> <!-- end of Smartphone Question Dropdown --> </div> <!-- end of second .row of inputs --> <div class="row"> <div class="col-md-12"><input type="submit" value="Submit"></div> </div> </form> 

If anyone has any ideas please let me know. I pull my hair out. I decided that I would be up all night with the problems associated with querying the database, or messing around with AJAX to make it polished, but instead I can't even go past the form representing the RAW data! Very frustrating. I hope someone there can see the problem.

For the record, this is my exact message after the form is redirected to signup1.php (yes, this goes to the correct page). In PHP, all I do is Var_dump the entire $ _POST variable.

 var_dump($_POST); 

And it shows me the following:

 array(0) { } 
+6
source share
6 answers

You must add a name attribute to the form fields.

For instance:

 <input name="phone" type="text" id="phone" class="form-control" placeholder="801-321-9876"> 
+31
source

Try adding a name attribute for each input tag and select tag. It needs to be done.

+2
source

If anyone else has this problem *

I had the same problem. My problem was that I forgot the method = "post" attribute on the form element

+1
source

Use redacted script:

 <form action="actions/signup1.php" method="post"> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="name">Name:</label> <input type="text" id="name" name="name" class="form-control" placeholder="John Smith"> </div> </div> <!-- end of name input column --> <div class="col-md-6"> <div class="form-group"> <label for="phone">Phone Number:</label> <input name="phone" type="text" id="phone" class="form-control" placeholder="801-321-9876"> </div> </div> <!-- end of phone number input column --> </div> <!-- end of first .row of inputs --> <div class="row"> <div class="col-md-6 column-sm-12"> <div class="form-group"> <label for="email">Email Address:</label> <input type="text" name="email" id="email" class="form-control" placeholder=" johnsmith@me.com "> </div> </div> <!-- end of email address input column --> <div class="col-md-3 col-sm-6"> <div class="form-group"> <label for="city">City:</label> <select id="city" name="city" class="form-control"> <option>Las Vegas</option> <option>Salt Lake City</option> <option>I'll Choose a Default Later...</option> </select> </div> </div> <!-- end of city dropdown --> <div class="col-md-3 col-sm-6"> <div class="form-group"> <label for="type-of-phone">Type of Phone:</label> <select id="type-of-phone" name="type-of-phone" class="form-control"> <option>iPhone</option> <option>Android</option> <option>Windows Phone</option> <option>Blackberry</option> <option>Other Cellphone</option> <option>Landline</option> </select> </div> </div> <!-- end of Smartphone Question Dropdown --> </div> <!-- end of second .row of inputs --> <div class="row"> <div class="col-md-12"><input type="submit" value="Submit"></div> </div> </form> 

Output:

enter image description here

0
source

If you want to post data using the html form tag, you can simply check it out

 print_r($_POST); 
0
source

Try to provide a name for each field of your input fields, as well as provide a name for sending. Thus, your problem will be solved.

0
source

Source: https://habr.com/ru/post/957765/


All Articles