/    Sign up×
Community /Pin to ProfileBookmark

Holding onto POST variables after clicking a link

I’m certain this is possible, I just have yet to figure out exactly how. I’ll try to simplify my problem into an easier example and break it down to the need-to-know information as best I can, but since I’m not an expert, I’ll pass along any information that seems helpful in solving the problem.

I’m writing a Citation Generator (it makes bibliography entries) for my college, and the script for the generator itself is almost complete. It’s basically a complex form submitted POST, where on every form-resubmit (and there are a lot of them), all of the POST variables are maintained through hidden tags generated at the top of the form. Since the script is already over 7,000 lines long, I have no intention of recoding anything at great lengths, so if someone here is to suggest I start using a Session or Cookies, it needs to be something that I can just copy in and have working transparently.

Here’s the problem:

The script itself is going to be part of a larger web page, which php-includes the header, the generator script, and the footer. On the sidebar of the page, I have various url-encoded links that will act as hot-links (automatically building the form up a bit) and also serve up auxillary information on the topic that wouldn’t appear otherwise.

here’s the URL, since that explanation may have been confusing: [url]http://ugoto.calvin.edu/~jas26/index.php[/url]

My problem is that every time a link is clicked, I lose all of the POST data that the form has been storing up. Also, when I click a link, the GET value is converted to a POST (inside the included script). I want said links to effectively MODIFY my POST data, and not lose it with every click.

In the end, the three standard links up top (APA, MLA, Chicago) should all act like switches, just the same as the first Select box in the form does. Meanwhile, the sidebar (Book, Periodical) needs to also be able to change the $_POST[‘resource’] variable.

How can I make sure that the POST variables aren’t reset when a user clicks one of those href links? Everything I’ve tried with hidden tags (in the form as well as an additional function making them in the main index.php file) hasn’t done any good at all.

I hope someone follows and sees what it is I’m wanting here, if not I’d be happy to try again at describing it.

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@crh3675Jul 21.2004 — So basically, if a user has entered data into the name fields, you want to store that via a session or somehow. So when they pull up any form regardless of how they get there, those fields are automatically filled in. Correct??
Copy linkTweet thisAlerts:
@justin1754authorJul 21.2004 — Yeah, exactly.

If I did use a PHP session, I would want to have it completely autonomous from the rest of the script.

Right now I run through every variable in the post array and make a hidden tag for it. How can I do the same thing easily with sessions: run through post, do something i heard called serialize everything, and then unpack it with unserialize on a reload and transfer it back to Post all at the beginning of the script. Will That work? And if so, what would the code look like?
Copy linkTweet thisAlerts:
@crh3675Jul 21.2004 — Assuming that you popuplate your fields using

<input type="Text" name="name="value="<?=$_POST["name"]?>">

this may work for you

[code=php]
session_start();

if(!empty($_POST)){

foreach($_POST as $key=$value){

$str="$_SESSION["$key"]="".addslashes($value)."";";
eval($str);
}
}else{

foreach($_SESSION as $key=$value){

$str="$_POST["$key"]="".addslashes($value)."";";
eval($str);
}
}
[/code]
Copy linkTweet thisAlerts:
@justin1754authorJul 21.2004 — It's complaining that this line brings a parse error:

[code=php]foreach($_POST_as_$key=$value){
[/code]


???
Copy linkTweet thisAlerts:
@crh3675Jul 21.2004 — [code=php]
session_start();

if(!empty($_POST) && is_array($_POST)){

foreach($_POST as $key=>$value){

$str="$_SESSION["$key"]="".addslashes($value)."";";
eval($str);
}
}else{

foreach($_SESSION as $key=>$value){

$str="$_POST["$key"]="".addslashes($value)."";";
eval($str);
}
}
[/code]
Copy linkTweet thisAlerts:
@justin1754authorJul 21.2004 — Ah, thought that was it, but I tried adding the > before removing the invisible characters BBEdit was inserting after pasting your code.

Anyway, it works absolutely perfectly now. You rock.

I owe you a beer.
×

Success!

Help @justin1754 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...