Use a button to reset form values

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ken

    Use a button to reset form values

    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($non e) { $_SESSION = array(); }
    ?>

    <form enctype="multip art/form-data" name="company_i nfo" 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>


  • Andy Hassall

    #2
    Re: Use a button to reset form values

    On Thu, 19 Aug 2004 22:52:32 GMT, "Ken" <kkrolski@wi.rr .com> wrote:
    [color=blue]
    >How can I reset the initial form variables that are set with session
    >statements when clicking on a button?[/color]

    With a reset button.



    [color=blue]
    >I tried this but the function was not called:
    ><?PHP
    >function reset_form($non e) { $_SESSION = array(); }
    >?>
    >
    ><form enctype="multip art/form-data" name="company_i nfo" method="post"
    >action="add_pi c.php">
    >
    ><input type="text" name="co_name" value ="<?PHP echo $_SESSION['co_name'];
    >?>" >
    >
    ><input type="reset" value="Reset" onClick ="<?PHP reset_form();?> ">[/color]

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

    --
    Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
    <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

    Comment

    • kingofkolt

      #3
      Re: Use a button to reset form values

      "Ken" <kkrolski@wi.rr .com> wrote in message
      news:QaaVc.6276 1$ju6.23056@twi ster.rdc-kc.rr.com...[color=blue]
      > 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($non e) { $_SESSION = array(); }
      > ?>
      >
      > <form enctype="multip art/form-data" name="company_i nfo" 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>
      >
      >[/color]

      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


      Comment

      • Sebastian Lauwers

        #4
        Re: Use a button to reset form values

        kingofkolt wrote:
        [color=blue]
        > 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.[/color]

        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="'.$_SER VER['PHP_SELF'].'" method="post">
        <input type="submit" value="Reset the $_SESSION array"
        name="reset" />
        </form>';

        }
        else {

        $_SESSION = array();

        echo 'Happy?';

        }
        ?>
        [color=blue]
        > BTW, there's this nice little manual at PHP.net that you may want to read.[/color]

        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...
        [color=blue]
        > - JP[/color]

        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

        Comment

        • kingofkolt

          #5
          Re: Use a button to reset form values

          "Sebastian Lauwers" <dacrashanddie@ nospam.9online. fr> wrote in message
          news:412538e4$0 $32654$626a14ce @news.free.fr.. .[color=blue]
          > kingofkolt wrote:
          >[color=green]
          > > Oh boy...
          > >
          > > A few pointers:
          > >
          > > 1. PHP is server-side. That means PHP does not act based on an[/color][/color]
          onClick="..."[color=blue][color=green]
          > > event handler. If you want $_SESSION variables to be cleared, the user[/color][/color]
          will[color=blue][color=green]
          > > have to send a whole new request to the server, because client-side[/color][/color]
          actions[color=blue][color=green]
          > > do not activate PHP scripts.
          > >
          > > 2. Are you looking for a button that will make the text field blank, or[/color][/color]
          a[color=blue][color=green]
          > > 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[/color][/color]
          handler[color=blue][color=green]
          > > for that.
          > >
          > > 3. The values submitted by the form are not stored in the $_SESSION
          > > variable. Access them using $_POST.[/color]
          >
          > 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="'.$_SER VER['PHP_SELF'].'" method="post">
          > <input type="submit" value="Reset the $_SESSION array"
          > name="reset" />
          > </form>';
          >
          > }
          > else {
          >
          > $_SESSION = array();
          >
          > echo 'Happy?';
          >
          > }
          > ?>
          >[color=green]
          > > BTW, there's this nice little manual at PHP.net that you may want to[/color][/color]
          read.[color=blue]
          >
          > 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...
          >[color=green]
          > > - JP[/color]
          >
          > 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[/color]

          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="...").


          Comment

          • Michael Austin

            #6
            Re: Use a button to reset form values

            kingofkolt wrote:
            <unnecessary stuff snipped>[color=blue]
            > 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="...").[/color]


            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... :)

            Comment

            • jimt

              #7
              Re: Use a button to reset form values

              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(actual ly a wierdess factor)
              and why my reset is working differently at different times.
              jimt

              In article <7bcVc.191440$e M2.188414@attbi _s51>, kingofkolt
              <jessepNOSPAM@c omcast.net> wrote:
              [color=blue]
              > 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="...").[/color]

              Comment

              • Ken

                #8
                Re: Use a button to reset form values

                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 " <jessepNOSPAM@c omcast.net> wrote in message
                news:7bcVc.1914 40$eM2.188414@a ttbi_s51...[color=blue]
                > "Sebastian Lauwers" <dacrashanddie@ nospam.9online. fr> wrote in message
                > news:412538e4$0 $32654$626a14ce @news.free.fr.. .[color=green]
                > > kingofkolt wrote:
                > >[color=darkred]
                > > > Oh boy...
                > > >
                > > > A few pointers:
                > > >
                > > > 1. PHP is server-side. That means PHP does not act based on an[/color][/color]
                > onClick="..."[color=green][color=darkred]
                > > > event handler. If you want $_SESSION variables to be cleared, the user[/color][/color]
                > will[color=green][color=darkred]
                > > > have to send a whole new request to the server, because client-side[/color][/color]
                > actions[color=green][color=darkred]
                > > > do not activate PHP scripts.
                > > >
                > > > 2. Are you looking for a button that will make the text field blank,[/color][/color][/color]
                or[color=blue]
                > a[color=green][color=darkred]
                > > > button that will reset the text field to its original value? Neither[/color][/color][/color]
                of[color=blue][color=green][color=darkred]
                > > > 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[/color][/color]
                > handler[color=green][color=darkred]
                > > > for that.
                > > >
                > > > 3. The values submitted by the form are not stored in the $_SESSION
                > > > variable. Access them using $_POST.[/color]
                > >
                > > 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="'.$_SER VER['PHP_SELF'].'" method="post">
                > > <input type="submit" value="Reset the $_SESSION array"
                > > name="reset" />
                > > </form>';
                > >
                > > }
                > > else {
                > >
                > > $_SESSION = array();
                > >
                > > echo 'Happy?';
                > >
                > > }
                > > ?>
                > >[color=darkred]
                > > > BTW, there's this nice little manual at PHP.net that you may want to[/color][/color]
                > read.[color=green]
                > >
                > > 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...
                > >[color=darkred]
                > > > - JP[/color]
                > >
                > > 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[/color]
                >
                > 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[/color]
                a[color=blue]
                > 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="...").
                >
                >[/color]


                Comment

                • Geoff Berrow

                  #9
                  Re: Use a button to reset form values

                  I noticed that Message-ID: <B5hVc.83741$6t 1.25857@twister .rdc-kc.rr.com>
                  from Ken contained the following:
                  [color=blue]
                  >To answer a few of the questions:
                  >2. Are you looking for a button that will make the text field blank?
                  > Yes[/color]
                  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.
                  [color=blue]
                  > 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=""[/color]
                  Indeed. HTML reset would not work.
                  [color=blue]
                  > 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.[/color]

                  So the reset part of the script needs to prevent the $_POST variables
                  being assigned, if true.[color=blue]
                  >
                  >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.[/color]

                  I doubt it will. But you seemed to have some basic misunderstandin g
                  about how server side processing works and the manual would help with
                  that.[color=blue]
                  >
                  >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.[/color]

                  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/

                  Comment

                  • Sebastian Lauwers

                    #10
                    Re: Use a button to reset form values

                    Ken wrote:
                    [color=blue]
                    > 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.[/color]

                    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.
                    [color=blue]
                    > 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.[/color]

                    For what i've learned, everyone keeps learning, PHP is so versatile that
                    it is truely difficult to say: I know everything about PHP.
                    [color=blue]
                    > 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.[/color]

                    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:



                    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.
                    [color=blue]
                    > Ken[/color]

                    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

                    Comment

                    Working...