2 replies
I am working on a project where I want to take any opt in form and count how many times it was submitted. After extensive research (I know that Javascript is client side and PHP is server side) I came up with a solution.

What I did was to add a tag to the beginning of the form with an "onsubmit" tag calling a Javascript which in turn submits a hidden form which posts to my PHP program that updates the databases.

This works great except... If I leave the opt in page and come back, it won't work anymore. I have tried everything that I can think of, I changed the hidden form action to post the vars directly without using the hidden inputs, I have tried changing it to open the file in a hidden div or even the main window (The php program has no output) Does anyone have any ideas why it will stop working when the window looses focus? the code is added below:

<form onsubmit="return OnButton1();" action="http://yahoo.com">
<input type="text" value="Your Name Here" />
<input type="text" value="Your Email Here" />

<input type="submit" value=" " />
</form>
</div>

<form name = "Formzilla" action = "http://www.mysite.com/lpage/maillist.php" method ="post">
<input type="hidden" name = "item" value = "1">
<input type = "hidden" name = "page" value = "3">
</form>
<script language="javascript">
function OnButton1()
{
document.Formzilla.submit();
return true;
}
</script>
#issue #javascript or php
  • Profile picture of the author BenB969
    Banned
    [DELETED]
    {{ DiscussionBoard.errors[1983811].message }}
    • Profile picture of the author danmart
      Sorry... The script will not post the hidden form. I have an implicit database call that would make an entry every time the program was called and I get nothing so I know that the form is not getting submitted.

      oh and I get no errors and the main form works just fine.

      An Update... I have found that If I refresh the page after leaving it and before I submit the form it will post the hidden form but not if I don't refresh the page.
      {{ DiscussionBoard.errors[1983823].message }}
      • Profile picture of the author BenB969
        Banned
        [DELETED]
        {{ DiscussionBoard.errors[1983884].message }}
        • Profile picture of the author danmart
          Originally Posted by BenB969 View Post

          I can't see why it doesn't work from the info you've given.

          However I can suggest another method.

          How about having just 1 form.
          The form will be sent to the php file in your server.
          The php file will add the data to your database.
          It will then send the user to the original form destination.

          This is a better way because it doesn't rely on the user browser.
          That would work in most situations but not this. This is part of a system where you can add ANY autoresponder code and the program adds the tracking code automatically. I have no way of knowing the autoresponder vars so I can pass them to the PHP handler.
          {{ DiscussionBoard.errors[1983906].message }}

Trending Topics