Page 1 of 1

Can you unset POST VARS?

Posted: Wed Jul 02, 2003 5:01 pm
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() ???

Posted: Wed Jul 02, 2003 5:10 pm
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? ;)

Posted: Wed Jul 02, 2003 5:30 pm
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 :(

Posted: Wed Jul 02, 2003 7:51 pm
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?

Posted: Wed Jul 02, 2003 9:43 pm
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:

Posted: Wed Jul 02, 2003 10:18 pm
by JPlush76
thanks guys,
I just did the manual code :(

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