简体   繁体   中英

PHP Form not posting all fields data

I have a form I am trying to submit. For the life of me, I can't figure out why none of the data from the fields is posting. Here is the form.

I've tried to change different input types and the name's but nothing is working.

UPDATE: I was able to fix the problem. 3rd party script was preventing posting of all data

Your code is confusing. you have id attributes o the submit button in two places. you also have id set to myform at form parameter. Which Id are you using to send the form. In your absence of your javascript and php backend. you can try the code below and see if it helps

        <script 
  src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> 
  type="text/javascript" charset="utf-8"></script>

<script>
$(document).ready(function(){

 $('#myForm').on('submit', function(event){
  event.preventDefault();
  $.ajax({
   url:"submit.php",
   method:"POST",
   data:$(this).serialize(),
   dataType:"html",
   beforeSend:function(){
alert('am about to submit');
   },
   success:function(data){
    $('#myresult').fadeIn('slow').prepend(data);
   }
  })
 });

});
</script>




// display ajax result in div below...
<div id="myresult"></div>


<form id="myForm" class="form" method="post">

<input type="text" class="form-control center-block" id="fname" placeholder="First Name" name="fname" required>

<input type="text" class="form-control center-block" id="lname"  placeholder="Last Name" name="lname" required>

<input type="email" class="form-control center-block" id="email"  placeholder="Email Address" name="email" required>

<input type="text" class="form-control center-block" id="location" value="modal"  placeholder="location" name="location" hidden>

<input type="button" class="btn-success btn-lg" name="submit" id="submit" value="Submit!"/>
</form>

submit.php

<?php
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$location = $_POST['location'];

//If everything were okay echo success

echo "success. myname is: $fname $lname and my email is: $email";

?>

You have actually two ids in the submit button:

<input type="button" 
  id="submitFormData" 
  onclick="SubmitFormData();" 
  class="btn-success btn-lg" 
  name="submit" 
  id="submit" 
  value="Submit!"
/>
  • id="submitFormData" AND id="submit"
  • Also you have a JS function called when onclick event SubmitFormData()

These things are pretty suspicious...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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