Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending vars to another script w/o form

Status
Not open for further replies.

salewit

Programmer
Oct 31, 2002
58
US
This is going to be a tough problem to describe. I have a PHP script that collects information from a form, then redirects to a password protected archive (Mailman). I need to send the username and password (to MailMan), but I can't do it in the FORM tag because I can't create the form tag until I collect the info. Hmmm this may be easier to show that explain:

filename: test.php

<?php
if ($entereddata==1) {
$username = "username";
$password = "password";
$url = " . $month . "/" . $year;
header ("Location: " . $url);
exit;
}
?>

<html><head></head><body>

<form method="post" action="test.php">
<input type='hidden' name='entereddata' value='1'>

<select name='month'>
<option>Select Month
<option>January
<option>February
<option>etc</select>

<select name='year'>
<option>Select Year
<option>2003
<option>2004
<option>2005</select>

<select name='type'>
<option>Read Thread Online
<option>Download Entire Thread</select>

<input type='submit' value="Go"></form>
</body></html>
 
But how can I set the FORM action field when the data I need is actually coming from the form? Inotherwords, I need to make the ACTION field go to any one of about 30 locations based on the form input. Kind of a form within a form thing I guess.

Based on user input, the ACTION field will need to look like one of these:


Along with that I need to pass the two hidden userid and password fields to get Mailman to work properly. I have no control of these archives.
 
Hi,
If you use ACTION to pass the variables, it will be in the querystring. This might be an option, if you make some kind of search-function, where you want your users to be able to bookmark the search-results. (like google).

You can in that case combine method="post", with action="foo.php?search=<?=$string?>"

But, as you said this contains username and Passwords, you can either:

Pass via <form> OR: Pass with session variables.
If you wish to pass via <form>, you can add this input:
<input type="hidden" name="password" value="<?=$password?>" />

Olav Alexander Mjelde
Admin & Webmaster
 
Ah, I get you now.

I'd go with session variables.

Basically, once they submit a form, start a session, record $_POST into a session variable (or $_GET) then redirect, then on the receiving page, start a session and retrieve the information.

If you don't have access to modify the receiving scripts, this is slightly more difficult... but it can be done.

But before even going down that route, do session variables work for you?
 
You could use JavaScript to alter the <form> action as well
 
Hmmm... I'll have to read up on $_POST. That may work. I'd show you guys the actually live examples, but it's for a private organization and they're insanely hung up on keeping access to members only.

But here is a real link to one of the archives:


When you click on that link, you'll be prompted for user and password by THAT script (I don't have any access to it). But if you do this:


It would skip the login procedure (if the uid and pw were correct). Of course I don't want this info in the URL. But it sounds like $_POST may work as long as the receiving script gets the variables. I'll read up on this and post my results. Thanks!
 
Hmmm it looks like $_POST works backwards to what I thought (it's for receiving variables??). I tried session_register("password"); and setting the variable, but that didn't work. The Mailman program I believe is written in Python. Maybe it won't take session variables?

I looked into Javascript, but I don't know a thing about it. I found this page and it looked like just what I needed until I got into it more. This is just an example to switch between two different possibilities. With my problem, I could have 72 different possibilities and I would need to "build" the resulting destination string. Something I don't know how to do in JS. I may have to start doing some serious reading.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top