By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,751 Members | 1,175 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,751 IT Pros & Developers. It's quick & easy.

Automatic Submission of Form

P: 196
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).
Sep 11 '08 #1
Share this Question
Share on Google+
6 Replies

Expert 5K+
P: 5,058

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.

Expand|Select|Wrap|Line Numbers
  1. ($myField = @$_POST['myField']) or $myField = "Default value";
Sep 11 '08 #2

P: 196
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.

Sep 12 '08 #3

Expert 5K+
P: 5,058
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:
Expand|Select|Wrap|Line Numbers
  1. # form.html
  2. <form action="action.php" method="post">
  3.   <input type="text" name="field" value="myValue" />
  4. </form>
  6. # action.php
  7. mysql_query("INSERT INTO whatever VALUES('{$_POST['field']}')");
And executing the "form.html" by a cron-job, you could simply do:
Expand|Select|Wrap|Line Numbers
  1. # action.php
  2. mysql_query("INSERT INTO whatever VALUES('myValue')");
And execute the "action.php"

Or better yet, you could do:
Expand|Select|Wrap|Line Numbers
  1. # action.php
  2. ($value = @$_POST['myValue']) or $value = "Default";
  3. mysql_query("INSERT INTO whatever VALUES('$value')");
And execute either the "action.php" by a cron-job or the "form.html" via a browser.
Sep 12 '08 #4

P: 196
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
Sep 13 '08 #5

Expert 5K+
P: 5,058
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:
Expand|Select|Wrap|Line Numbers
  1. // action.php
  2. or even
  3. /* action.php */
Doesn't do anything.
Sep 13 '08 #6

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

Thanks heaps for the input
Sep 14 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.