Can you unset POST VARS?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Can you unset POST VARS?

Post by JPlush76 »

what up all?

quickie... I know I can empty all session vars but lets say I have a form with 500 fields on it. I keep the value of those fields in case of errors. If the user submits a good record I want to clear that form so they can enter their next record.

Is there a way to empty all POST vars at once?

like session_unset() ???
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

until now it's an array like any other (except beeing auto-global).
So the following might not be sophisticated or good style but it's working

Code: Select all

<html><body><?php
if(count($_POST) > 0)
{
	echo '<pre>'; print_r($_POST); echo '</pre>';
	$_POST = array();
	echo '<pre>'; print_r($_POST); echo '</pre>';
}
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
	<input type="submit" /><br />
<?php for($i=65; $i!=91; $i++) { ?>
	<input tpye="text" name="<?php echo chr($i); ?>" value="<?php echo chr($i+32); ?>" />
<?php } ?>
</form>
</body></html>
But the question remains: Why? What is its purpose? ;)
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

what is the purpose of unseting the post vars?
so it clears out the fields for the next order.

I was leary about doing loops to unset all the POST vars. I was hoping there was a nice magic php function I was missing :(
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

clearing out because you have something like

Code: Select all

<input type="text" name="amount[order1]" value="<?php if (isset($_POST['amount']['order1'])) echo (int)$_POST['amount']['order1']; ?>" />
within your script?
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

JPlush76 wrote:what is the purpose of unseting the post vars?
so it clears out the fields for the next order.

I was leary about doing loops to unset all the POST vars. I was hoping there was a nice magic php function I was missing :(
I tried to do a loop to unset all active session variables, and it killed my php.exe. :roll:
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

thanks guys,
I just did the manual code :(

maybe someday I'll have my dream of unsetting all post vars lol ;)
Post Reply