Automatic Submission of Form – PHP

  php

Q(Question):

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).

A(Answer):

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:


($myField = @$_POST['myField']) or $myField = "Default value";

A(Answer):

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

A(Answer):

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:


# form.html
<form action="action.php" method="post">
<input type="text" name="field" value="myValue" />
</form>
# action.php
mysql_query("INSERT INTO whatever VALUES('{$_POST['field']}')");

And executing the "form.html" by a cron-job, you could simply do:


# action.php
mysql_query("INSERT INTO whatever VALUES('myValue')");

And execute the "action.php"

Or better yet, you could do:


# action.php
($value = @$_POST['myValue']) or $value = "Default";
mysql_query("INSERT INTO whatever VALUES('$value')");

And execute either the "action.php" by a cron-job or the "form.html" via a browser.

A(Answer):

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

A(Answer):

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:


// action.php
or even
/* action.php */

Doesn’t do anything.

A(Answer):

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

Thanks heaps for the input

LEAVE A COMMENT