Re: passing variables from forms to the same page repetatively
| From: | Tim Olsen | Date: | Wed, 18 Jul 2001 07:56:36 +0000 |
| Subject: | Re: passing variables from forms to the same page repetatively | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-58411@lists.php.net to get a copy of this message | ||
This function that matt sent to automatically write hidden inputs is awesome. it works great. I am only using the first function.
It's a great solution.
thanks
----Original Message Follows----
From: "maatt" <kynaston@GREENEGGSANDyahoo.com>
To: php-general@lists.php.net
Subject: Re: [PHP] passing variables from forms to the same page repetatively
Date: Tue, 17 Jul 2001 11:23:11 +0100
I was doing something similar just yesterday. Ended up with a little
function to automatically write hidden <input>s for every variable that's
submitted, whether posted or thru the url. Goes like this...
// put this somewhere in your form
<?php print get_param_inputs(); ?>
// the function itself
function get_param_inputs() {
global $HTTP_GET_VARS, $HTTP_POST_VARS;
$ret_str = "";
$params = array_merge($HTTP_GET_VARS, $HTTP_POST_VARS);
foreach ($params as $k=>$v) {
if (is_array($v)) {
foreach($v as $kk=>$vv) {
$ret_str .= '<input type="hidden" name="'."$k[$kk]".'
value="'.$vv.'">';
}} else {
$ret_str .= '<input type="hidden" name="'.$k.'" value="'.$v.'">';} } return $ret_str; } I also needed to append the variables to links on the same page (for page 1, page 2, page 3... type thing) so did this: <a href="<?php print $PHP_SELF.get_param_query() ?>">link</a> function get_param_query() { global $HTTP_GET_VARS, $HTTP_POST_VARS; $ret_str = ""; $params = array_merge($HTTP_GET_VARS, $HTTP_POST_VARS); $j = "?"; foreach ($params as $k=>$v) { if (is_array($v)) {
foreach($v as $kk=>$vv) {
$ret_str .= $j.urlencode("$k[$kk]=$vv");
$j = "&";
}
}
else {
$ret_str .= $j.urlencode("$k=$v");
$j = "&";
}
}
return $ret_str;
}
Won't work if you're nesting arrays within arrays, but I'm not a recursive
type. Hope it helps,
Matt
"David Robley" <huntsman@www.nisu.flinders.edu.au> wrote in message
news:01071716134101.29979@www...
On Tue, 17 Jul 2001 15:41, Tim Olsen wrote:-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.comPeople, I have 4 forms in four seperate html pages included directly (no links to includes) in the same .php file, i have it so all the form actions is php.self, so when each form is submitted it goes on to display the next form in line, using if and else statements, of course. I want to be able to use variables created by the first form in the html part of the last form. What is the best way to do this? So far, I can only use variables on the next page (form) that is written out. After that those variables have no value. Is there some way to submit all variables present and assigned with the submission of each form? If I make the forms a seperate include file, instead of having them in-line, how does this change the ways variables are passed or submitted by each form? Thanks, - Tim _________________________________________________________________If I understand what you are saying: those variables don't exist until you SUBMIT the form. You can demonstrate this by looping through and displaying your POST or GET vars at the beginning of the form and see what happens when you first open the page, and when it calls itself. And re-reading, I think what you may want is hidden fields. You want part one to call part 2, and retain values from part 1, etc? Echo the values into hidden fields in each step of the process. <INPUT TYPE=hidden NAME=whatever VALUE="<?php echo $whatever ?>"> --David Robley Techno-JoaT, Web Maintainer, Mail List Admin, etc CENTRE FOR INJURY STUDIES Flinders University, SOUTH AUSTRALIAI always lie. In fact, I'm lying to you right now!