0

I want to make a form auto click based on referrer site..

My url is http://example.com/from/

<form action="" method="post">
<input name="name" value="Jhon" type="text">
<input name="email" value="address@example.com" type="email">
<input name="age" value="28" type="text">
</form>

What I would like, is that when a user come from a certain URL the form will automatically be submitted (auto-clicked). However when the user comes directly to this page, or from a specific site (such as my own) the form will not be submitted.

Is it possible to do this?

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
NoDiv_NoClass
  • 138
  • 5
  • 20

3 Answers3

0

Try using:

string = document.referrer;

For more information on this, you should see this for more information concerning this.

After you have gotten the URL, you need to decide what to do with it. You can use document.ready:

$( document ).ready(function() {
    //logic
});

Make something that x has the value of "example website" then do:

$("#form_id").submit();

Else do nothing.

Also, this might be a duplicate of this except that this user purely needs a function to run on the document being finished. Finally this solution needs Jquery.

Community
  • 1
  • 1
Alexander Craggs
  • 7,874
  • 4
  • 24
  • 46
  • I use like this... but not work... – NoDiv_NoClass Aug 17 '14 at 23:14
  • Aren't you missing curly brackets for if statement, although possibly not necessary, might help. Also, make sure that you have imported jQuery. – Alexander Craggs Aug 17 '14 at 23:40
0

Something like this?

if (document.referrer == "certain_url")
$("#form_id").submit();
Scyld de Fraud
  • 225
  • 1
  • 7
0

You should use "match" function to submit the form when the user came from any page of the site anything.com

$(document).ready(function(){ 
  var uri = document.referrer;

  if (uri.match(/anything.com/)){
    $("#yourForm").submit();
  }
});