1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

counting form submissions

Discussion in 'Programming' started by ferret77, Jul 19, 2005.

  1. #1
    I have a new affilate who supplies a form to host on my site but submits to url located elsewhere.

    Is there an easy way to count the nubmer of times the form is submitted?
     
    ferret77, Jul 19, 2005 IP
  2. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Have the form submit to a url at your site, where you have a script to increment a counter (save to a text file or DB), then redirect to the destination url, along with all the (presumably) POST data.
     
    exam, Jul 19, 2005 IP
  3. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Redirection never works for POST'ed forms and if the form-handling app expects a POST'ed form, this technique will not work.

    Another way to capture some form submissions is to use client-side JavaScript and request some file from the source website and then continue with the form. For example:

    <script type="text/javascript">
    function onFormSubmit(form)
    {
    document.getElementById("im1").src = "some-image.gif?field=" + form.elements.i1.value + "&amp;field2=" + form.elements.i2.value;
    return true;
    }
    </script>

    <body>
    <form method="POST" action="anything.html" onsubmit="return onFormSubmit(this)">
    <input id="i1"><input id="i2">
    <input type="submit" value="submit">
    </form>
    <img id="im1" src="some-image.png">
    </body>

    J.D.
     
    J.D., Jul 19, 2005 IP
  4. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You're right JD, I really didn't think about my response before posting it. :( It should work however, to have the php tracking script actually make a POST request to the end server after logging the form submission.... I think :) Your JS solution looks a lot simpler tho.
     
    exam, Jul 19, 2005 IP
  5. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You are right - a subsequent PHP post would be a good solution because JS will not be always available. JS is really the only option if somebody's running an HTML-only site or if the server-side scripting doesn't support or isn't allowed to send HTTP requests to third-party servers.

    J.D.
     
    J.D., Jul 19, 2005 IP