By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,319 Members | 2,361 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,319 IT Pros & Developers. It's quick & easy.

Use a button to reset form values

P: n/a
Ken
How can I reset the initial form variables that are set with session
statements when clicking on a button?

I tried this but the function was not called:
<?PHP
function reset_form($none) { $_SESSION = array(); }
?>

<form enctype="multipart/form-data" name="company_info" method="post"
action="add_pic.php">

<input type="text" name="co_name" value ="<?PHP echo $_SESSION['co_name'];
?>" >

<input type="reset" value="Reset" onClick ="<?PHP reset_form();?>">

</form>
Jul 17 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
On Thu, 19 Aug 2004 22:52:32 GMT, "Ken" <kk******@wi.rr.com> wrote:
How can I reset the initial form variables that are set with session
statements when clicking on a button?
With a reset button.

http://www.w3.org/TR/html4/interact/...l#reset-button
http://www.w3.org/TR/html4/interact/...#initial-value
I tried this but the function was not called:
<?PHP
function reset_form($none) { $_SESSION = array(); }
?>

<form enctype="multipart/form-data" name="company_info" method="post"
action="add_pic.php">

<input type="text" name="co_name" value ="<?PHP echo $_SESSION['co_name'];
?>" >

<input type="reset" value="Reset" onClick ="<?PHP reset_form();?>">


You can't call a PHP function from the client.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2

P: n/a
"Ken" <kk******@wi.rr.com> wrote in message
news:Qa*******************@twister.rdc-kc.rr.com...
How can I reset the initial form variables that are set with session
statements when clicking on a button?

I tried this but the function was not called:
<?PHP
function reset_form($none) { $_SESSION = array(); }
?>

<form enctype="multipart/form-data" name="company_info" method="post"
action="add_pic.php">

<input type="text" name="co_name" value ="<?PHP echo $_SESSION['co_name'];
?>" >

<input type="reset" value="Reset" onClick ="<?PHP reset_form();?>">

</form>


Oh boy...

A few pointers:

1. PHP is server-side. That means PHP does not act based on an onClick="..."
event handler. If you want $_SESSION variables to be cleared, the user will
have to send a whole new request to the server, because client-side actions
do not activate PHP scripts.

2. Are you looking for a button that will make the text field blank, or a
button that will reset the text field to its original value? Neither of
these are PHP-related. If you want to make the text field blank, use
JavaScript. If you want to reset it to it's original value, use <input
type="reset" value="Reset">. You don't need an onClick="..." event handler
for that.

3. The values submitted by the form are not stored in the $_SESSION
variable. Access them using $_POST.

BTW, there's this nice little manual at PHP.net that you may want to read.

- JP
Jul 17 '05 #3

P: n/a
kingofkolt wrote:
Oh boy...

A few pointers:

1. PHP is server-side. That means PHP does not act based on an onClick="..."
event handler. If you want $_SESSION variables to be cleared, the user will
have to send a whole new request to the server, because client-side actions
do not activate PHP scripts.

2. Are you looking for a button that will make the text field blank, or a
button that will reset the text field to its original value? Neither of
these are PHP-related. If you want to make the text field blank, use
JavaScript. If you want to reset it to it's original value, use <input
type="reset" value="Reset">. You don't need an onClick="..." event handler
for that.

3. The values submitted by the form are not stored in the $_SESSION
variable. Access them using $_POST.
4. If you want to reset the $_SESSION array by clikcing on a nice little
button use this:

<?php

if (!isset ($_POST['reset'])) {

echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<input type="submit" value="Reset the $_SESSION array"
name="reset" />
</form>';

}
else {

$_SESSION = array();

echo 'Happy?';

}
?>
BTW, there's this nice little manual at PHP.net that you may want to read.
Yeah, indeed, print it out, and read one chapter every night before
going to bed. Honnestly, you could be a guru for PHP4/5 when PHP XXIII
will be out and running...
- JP


Best regards,
Sebastian
--
The most likely way for the world to be destroyed,
most experts agree, is by accident.
That's where we come in; we're computer professionals.
We cause accidents.
--Nathaniel Borenstein
Jul 17 '05 #4

P: n/a
"Sebastian Lauwers" <da***********@nospam.9online.fr> wrote in message
news:41***********************@news.free.fr...
kingofkolt wrote:
Oh boy...

A few pointers:

1. PHP is server-side. That means PHP does not act based on an onClick="..." event handler. If you want $_SESSION variables to be cleared, the user will have to send a whole new request to the server, because client-side actions do not activate PHP scripts.

2. Are you looking for a button that will make the text field blank, or a button that will reset the text field to its original value? Neither of
these are PHP-related. If you want to make the text field blank, use
JavaScript. If you want to reset it to it's original value, use <input
type="reset" value="Reset">. You don't need an onClick="..." event handler for that.

3. The values submitted by the form are not stored in the $_SESSION
variable. Access them using $_POST.
4. If you want to reset the $_SESSION array by clikcing on a nice little
button use this:

<?php

if (!isset ($_POST['reset'])) {

echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<input type="submit" value="Reset the $_SESSION array"
name="reset" />
</form>';

}
else {

$_SESSION = array();

echo 'Happy?';

}
?>
BTW, there's this nice little manual at PHP.net that you may want to

read.
Yeah, indeed, print it out, and read one chapter every night before
going to bed. Honnestly, you could be a guru for PHP4/5 when PHP XXIII
will be out and running...
- JP


Best regards,
Sebastian
--
The most likely way for the world to be destroyed,
most experts agree, is by accident.
That's where we come in; we're computer professionals.
We cause accidents.
--Nathaniel Borenstein


To me it sounded more like he wanted to clear the form than the $_SESSION
variable, and tried to go about doing that by clearing the $_SESSION
variable, which isn't necessary. And about the sarcasm, it seems there are a
lot of people lately asking how to do something with PHP that can clearly
only be achieved using client-side scripts (Ex: trying to run the
reset_form() PHP function using onClick="...").
Jul 17 '05 #5

P: n/a
kingofkolt wrote:
<unnecessary stuff snipped>
And about the sarcasm, it seems there are a
lot of people lately asking how to do something with PHP that can clearly
only be achieved using client-side scripts (Ex: trying to run the
reset_form() PHP function using onClick="...").

There are two major problems as I see them.

1) those who don't want to read the docs and expect everyone else to write their
code for them
2) those that don't understand what is they are doing even if they did read the
docs. (ex: trying to do client-side processing on a server-side language...
onclick(<?php...)

-- and no... I am no PHP guru, a newbie for approx. 6 months with PHP, but have
worked with many, many scripting languages over the years... OS, CGI and Web in
many flavors of Unix, Linux, DOS, RSX11-M, RSTS, OpenVMS/DCL (my personal
favorite) just to name a few.

The hardest thing for the "kids" these days is knowing which language to use for
any particular function or application. There are still reasons to use FORTRAN,
ADA and COBOL where C and it's derivatives fall short. PHP and Perl are very
"Unix/C like and if you don't understand C, you will never understand PHP. But
If you understand PHP and by extension Perl, then you might actually be able to
understand C.

Just remember. ALL languages (scripting and compiled) do exactly the same
things, they just use different syntax. Some do some things better than others
and visa-versa... and any language produced by M$ is garbage that bloats the
size and efficiency of any application.

Thought for today: Ignorance can be cured. Stupidity can't - (well sometimes a
2x4 helps, but most cases are hopeless)

--
Michael Austin.
Consultant - No longer Available.
Donations still welcomed. Http://www.firstdbasource.com/donations.html
:)
PS. I will be assuming the role of Sr. Technical Analyst at one of the largest
privately held corporations in the country (USA). I will continue to use PHP
and other scripting languages as necessary and will continue to help those that
can't seem to help themselves... :)
Jul 17 '05 #6

P: n/a
personally i failed to see the client side only part myself. i have
been working on both php and html for trying to reset a form myself for
the last couple days. i am finding that reseting a form is not always
simple. but the comment on client side versus server side does tell me
where to look for one of my reset problems(actually a wierdess factor)
and why my reset is working differently at different times.
jimt

In article <7bcVc.191440$eM2.188414@attbi_s51>, kingofkolt
<je**********@comcast.net> wrote:
asking how to do something with PHP that can clearly
only be achieved using client-side scripts (Ex: trying to run the
reset_form() PHP function using onClick="...").

Jul 17 '05 #7

P: n/a
Ken
Kingofkolt thanks for the suggestion.

It is interesting how others that comments on this question only say it
"cannot" be done because ....

While knowledgeable people like yourself offer creative thoughts on the
problem.

The problem is the user enters data into the form which must be reset, yes I
know about the reset command in html.

When the user returns to the form, the initial values are set by session
data (data and calculations) from a number of pages past the form.

I was looking for a means of resetting both with one button. The reason I
left the onClick to stimulate thought on how to reset both users text &
session initiated values with one button which could include a subroutine.

To answer a few of the questions:
2. Are you looking for a button that will make the text field blank?
Yes
or a button that will reset the text field to its original value
No, the initial values are set by sessions after returning to the form;
sessions must also be reset. Initially, the initial value=""
I prefer not to use JavaScript for security reason; part of the form
contains credit card numbers. I only use JavaScript for validation.

3. The values submitted by the form are not stored in the $_SESSION
variable. Access them using $_POST.
Actually, the initial values are stored in sessions variables after the
user returns to the form.

As far as the nice little manual on PHP, I searched it and could not find
any help on resetting html form text and PHP-session initiated values in a
form. I would be interested if the others can point to a section that
covers both.

I am also new the this language. I have only written about 150 pages for
this website utilizing HTML, JavaScript, PHP and MySql.
I am still learning.

Thanks again for taking the time to send a helpful suggestion. It is people
like you who help us to learn. The others just criticize.

Ken

"kingofkolt" <je**********@comcast.net> wrote in message
news:7bcVc.191440$eM2.188414@attbi_s51...
"Sebastian Lauwers" <da***********@nospam.9online.fr> wrote in message
news:41***********************@news.free.fr...
kingofkolt wrote:
Oh boy...

A few pointers:

1. PHP is server-side. That means PHP does not act based on an onClick="..." event handler. If you want $_SESSION variables to be cleared, the user will have to send a whole new request to the server, because client-side actions do not activate PHP scripts.

2. Are you looking for a button that will make the text field blank, or
a
button that will reset the text field to its original value? Neither
of these are PHP-related. If you want to make the text field blank, use
JavaScript. If you want to reset it to it's original value, use <input
type="reset" value="Reset">. You don't need an onClick="..." event
handler for that.

3. The values submitted by the form are not stored in the $_SESSION
variable. Access them using $_POST.


4. If you want to reset the $_SESSION array by clikcing on a nice little
button use this:

<?php

if (!isset ($_POST['reset'])) {

echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<input type="submit" value="Reset the $_SESSION array"
name="reset" />
</form>';

}
else {

$_SESSION = array();

echo 'Happy?';

}
?>
BTW, there's this nice little manual at PHP.net that you may want to

read.

Yeah, indeed, print it out, and read one chapter every night before
going to bed. Honnestly, you could be a guru for PHP4/5 when PHP XXIII
will be out and running...
- JP


Best regards,
Sebastian
--
The most likely way for the world to be destroyed,
most experts agree, is by accident.
That's where we come in; we're computer professionals.
We cause accidents.
--Nathaniel Borenstein


To me it sounded more like he wanted to clear the form than the $_SESSION
variable, and tried to go about doing that by clearing the $_SESSION
variable, which isn't necessary. And about the sarcasm, it seems there are

a lot of people lately asking how to do something with PHP that can clearly
only be achieved using client-side scripts (Ex: trying to run the
reset_form() PHP function using onClick="...").

Jul 17 '05 #8

P: n/a
I noticed that Message-ID: <B5*******************@twister.rdc-kc.rr.com>
from Ken contained the following:
To answer a few of the questions:
2. Are you looking for a button that will make the text field blank?
Yes Then since the values are the values of the session variables, you
simply need to reset the session variables to "" when the script detects
that the 'reset' button has been pressed. This can be another submit
button.
or a button that will reset the text field to its original value
No, the initial values are set by sessions after returning to the form;
sessions must also be reset. Initially, the initial value="" Indeed. HTML reset would not work.
I prefer not to use JavaScript for security reason; part of the form
contains credit card numbers. I only use JavaScript for validation.

3. The values submitted by the form are not stored in the $_SESSION
variable. Access them using $_POST.
Actually, the initial values are stored in sessions variables after the
user returns to the form.
So the reset part of the script needs to prevent the $_POST variables
being assigned, if true.
As far as the nice little manual on PHP, I searched it and could not find
any help on resetting html form text and PHP-session initiated values in a
form. I would be interested if the others can point to a section that
covers both.
I doubt it will. But you seemed to have some basic misunderstanding
about how server side processing works and the manual would help with
that.
I am also new the this language. I have only written about 150 pages for
this website utilizing HTML, JavaScript, PHP and MySql.
I am still learning.

Thanks again for taking the time to send a helpful suggestion. It is people
like you who help us to learn. The others just criticize.


The sum total of the advice seem to have put you well on the way to a
solution. However, I'm not sure why you are using sessions for this at
all.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #9

P: n/a
Ken wrote:
Kingofkolt thanks for the suggestion.

It is interesting how others that comments on this question only say it
"cannot" be done because ....

While knowledgeable people like yourself offer creative thoughts on the
problem.
It is interesting how people that ask info the wrong way, think they are
right when someone understands them, worse, when this person seems to be
quite smart. It is then very interesting how the faulty person tries to
get the smart guy to like him, wether it is by telling him he's a good
guy, and the others are jerks.

While most of the people who answered to this post only posted
constructive messages, i said most, don't go quoting the first that
didn't absolutely say something helpfull.
I am also new the this language. I have only written about 150 pages for
this website utilizing HTML, JavaScript, PHP and MySql.
I am still learning.
For what i've learned, everyone keeps learning, PHP is so versatile that
it is truely difficult to say: I know everything about PHP.
Thanks again for taking the time to send a helpful suggestion. It is people
like you who help us to learn. The others just criticize.
No, the "others" as you say, could do worse than criticizing. They could
be sending over trolls. You know, critic isn't such a bad thing, it
allows you to see your errors, and not forgetting them in the future.
You will also notice that there is nothing as valuable as users (of
one's website) criticizing your website.

BTW: You should prolly read this:

http://tk.digiserv.net/tofu.txt

And maybe some faq's on how to answer on newsgroup. Maybe more
importantly, how to ask questions, and learn not to flame when not
getting the answer you expected.
Ken


Best regards,
Sebastian
--
The most likely way for the world to be destroyed,
most experts agree, is by accident.
That's where we come in; we're computer professionals.
We cause accidents.
--Nathaniel Borenstein
Jul 17 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.