Automatic Submission of Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chazzy69
    New Member
    • Sep 2007
    • 196

    Automatic Submission of Form

    Ok two questions-

    First is it possible to replicate javascripts automatic submit with a php function, i want to do this due to the fact we i run a cron job it wont run javascript.

    Second If the above is not possible i need to transfer information from the intial page to another another .php and acts similar to the php form in that when u hit submit it will post the information to the other .php page and then opens that page.

    The reason i trying to achieve this is i want a server to run the script with out me having to activate it (i.e. cron jobs).
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    So you are trying to make a cron-job that triggers a local PHP script, which is meant to accept form data?

    Why not just create a second page, identical to the original, with the data hard-coded into variables? You could even create default values for the original code, in case the data wasn't passed from the form.

    Like:
    [code=php]
    ($myField = @$_POST['myField']) or $myField = "Default value";
    [/code]

    Comment

    • chazzy69
      New Member
      • Sep 2007
      • 196

      #3
      Thats sounds like a good idea so how do i post the form automatically to send the data to the second page or just post the varibles i need.


      Thanks

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        The point of HTML forms is to get data from remote clients to your server. If your scripts are meant to be executed with static data, by the server, there is no need to bother with that, you can simply hard-code the data into the code.

        Like, rather than doing:
        [code=php]
        # form.html
        <form action="action. php" method="post">
        <input type="text" name="field" value="myValue" />
        </form>

        # action.php
        mysql_query("IN SERT INTO whatever VALUES('{$_POST['field']}')");
        [/code]
        And executing the "form.html" by a cron-job, you could simply do:
        [code=php]
        # action.php
        mysql_query("IN SERT INTO whatever VALUES('myValue ')");
        [/code]
        And execute the "action.php "

        Or better yet, you could do:
        [code=php]
        # action.php
        ($value = @$_POST['myValue']) or $value = "Default";
        mysql_query("IN SERT INTO whatever VALUES('$value' )");
        [/code]
        And execute either the "action.php " by a cron-job or the "form.html" via a browser.

        Comment

        • chazzy69
          New Member
          • Sep 2007
          • 196

          #5
          Just wondering how does the line


          [PHP]# action.php[/PHP]


          actually work??

          I tried this but it didn't seem to do anything, is it ment to execute another .php page???


          Thanks for the help

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            No that's just a comment.
            Was my way of saying that the following code should be in a file called "action.php " :)

            It's the same as doing:
            [code=php]
            // action.php
            or even
            /* action.php */
            [/code]
            Doesn't do anything.

            Comment

            • chazzy69
              New Member
              • Sep 2007
              • 196

              #7
              I think i worked out how to call another file, using Curl.

              Thanks heaps for the input

              Comment

              Working...