Jump to content

Automatically submitting 'POST' data to a URL in your script.


jspringfield

Recommended Posts

Hi All,

I'm a noob, green enough to blend into a pile of grass. Can someone help pls?

As stated in the subject.  I have a webpage which accepts data from a form on another wepage.
What I would like to do is automatically send data from variables in my PHP script to the other page. Rather than using the form.
I also want to do several iterations of this from within a loop. So I don't want to be redirected.. just to send the data.

Any help is much appreciated.
Thanx.
Hi jspringfield,


  If the information you want to make available to other pages is not sensitive then you can use sessions, like so.

// start the session then give it a name.
session_start();
session_name('any_name_you_want');

// create session variable like this-
$_SESSION['variable_name'] = "This is a test of PHP sessions";

// use them like this-
echo "session variable show your secrets now: " . $_SESSION['variable_name'];



These session variables will be unique to each user and follow them throughout your site. They will be active as long as the user has their browser open unless you set them to expire after a specified time.


cmccully
Thanx for the info.

Let me elaborate a little.
The user has some data to send to a database.

Page A has a form on it containing a text area, and  standard text input (to enter a password) and a submit button (action is to invoke Page B).
The User types the data, clicks submit and is redirected to page B.

Page B accepts the POST variables from page a and runs a script updating a database with the data from the page A form.
This age then prints a status, succesful entry, invalid, etc, etc.


Ok:
I have lots of records of data to enter...
What I am trying to create is a Page C.

Page C contains a For Loop which repeats until all data has been posted to Page B.
I don't want the user to be redirected to page B.. I just want to set the variables (usually set by the form)
and have the Page C script automatically post them to Page B. As if they had come from a form.

I have tried the following:
          I made a link to Page B plus ?a=****&b=*****
          Page B accepts, but you need to click it. This is where I need the automation.

          I tried include (Page B) in the Page C script.
          This just slapped Page in the Page C Browser.

I'm currently examinig the possibility of using javascript to initiate a submit without redirecting.

Hope this makes things a bit clearer.. am I on the right path?

Thanks for your help.
What about using the same page and recursively calling it to perform the functions required by each page?


have the page submit a hidden field then read the vallue of the field and use a swith statement to perform the function needed. Use the default case to perform the functions that page A would perform. That page sets the field value to something like 'page_b', then your case for 'page_b' would do its business then set the field to 'page_c'.  Because you have not really left the page all your variables will still be available.

I use this approach all the time when I have a form that needs to be filled in. The initial load of the page displays a blank form. When the form is submitted I check that all the fields have been entered and the data is appropriate. If anything is wrong, I display the form again. I embed php in the form elements to echo the values that were entered the last time.

It looks something like this:

[quote]<?php
echo"<form name='form1' method='post' action='login.php'>
  <p>
<label>
Username:
<input name='username' type='text' id='username' value='$username'>
</label>
  </p>
  <p>
<label>
Password:
<input name='password' type='password' id='password' value='$password'>
</label>
<input name='req' type='hidden' id='req' value='process'>
  </p>
  <p>
<label>
<input type='submit' name='Submit' value='Submit'>
</label>
  </p>
  <p>&nbsp;</p>
</form>";


// Determin if form has been submitted.
$req = (!isset($_REQUEST['req'])) ?'default' : $_REQUEST['req'];
switch($req)
{
case "process"; // Form HAS been submitted.

// Do what you want here.....

break;



default:
// HTML has not been accessed yet so load page.
echo"<form name='form1' method='post' action='login.php'>
  <p>
<label>
Username:
<input name='username' type='text' id='username' value='$username'>
</label>
  </p>
  <p>
<label>
Password:
<input name='password' type='password' id='password' value='$password'>
</label>
<input name='req' type='hidden' id='req' value='process'>
  </p>
  <p>
<label>
<input type='submit' name='Submit' value='Submit'>
</label>
  </p>
  <p>&nbsp;</p>
</form>";


break;

?>
[/quote]


The above code is not complete but shows what I am talking about, hope this helps.




cmccully

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.