0

I have a form in my web page and I want to submit form data automatically when user open this on his web browser. This form contain fixed data from my side and use didnt have to add any data. So here is my form code...

<form action="data.php" method="post" enctype="plain" id="theForm">   
<input type="text" name="Visitor" value="FIXED-DATA-FROm-ME" />
<input type="submit" value="Send" />
</form>

How to do this? Please share some simple steps or light coding...

5 Answers5

1

Yes, You can do this using JavaScript too. Just add the below JavaScript code on your form page and its done. When any of your visitor open this page then all the form data will be submit automatically...

<script type="text/javascript">
window.onload = function() {
    var form = document.getElementById("theForm");
    form.submit();
}
</script>
Muhammad Hassan
  • 1,224
  • 5
  • 31
  • 51
0

If you dont want the user to be redirected, but you want to do it in the background, you should use ajax. Like:

$.ajax({
        url: 'data.php',
        type: 'post',
        dataType: 'json',
        data: $('form#theForm').serialize(),
        success: function(data) {
                   ...  success ...
                 }
});
netdigger
  • 3,659
  • 3
  • 26
  • 49
0

you can try this

Jquery :

$(document).ready(function(){
  $('#theForm').submit();
});

Javascript:

window.onload = function() {
   document.getElementById("theForm").submit();
}
Satish Sharma
  • 9,547
  • 6
  • 29
  • 51
0

If all the data are static,You dont need the form at all. call an ajax page on page load (document.ready()) and in the ajax page you just insert your data to the database table

Ashish
  • 188
  • 1
  • 2
  • 11
0

Do any of the following:

  • Using javascript onload method

    window.onload=function(){ var form = document.getElementById("theForm"); form.submit(); };

  • Using onload with body tag

    Make a function in javascript

    function myFunction() { var form = document.getElementById("theForm"); form.submit(); }

    Add following to the body tag in html

    <body onload="myFunction()">

  • Using jquery .ready() function See here

raghavsood33
  • 749
  • 7
  • 17