how to retain the value of form??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sweetline priya
    New Member
    • Jan 2009
    • 16

    #1

    how to retain the value of form??

    hi friends..

    in my page the form contains 10 textboxes. the user has to fill these textfields.

    if the user made any mistake in entering value in any textbox, in the button click, a message is displayed to intimate the user like ' u wrongly enter the value'.. in button click all the textbox values are erased. so can anybody tell me how to retain the value of textbox(without GET method because it is an unsecured one.. since all the values are displayed in address bar)

    and i need to retain in the same page, without moving to some other page... can anybody help me plz.....
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Well are you using POST? If so, your data will still be in the POST array (if you submit to the same page). So, for your input's value attribute, just echo the value from the POST array.

    Code:
    <input type="text" name="username" value="<?php echo @$_POST['username']; ?>" />

    Comment

    • sweetline priya
      New Member
      • Jan 2009
      • 16

      #3
      Originally posted by Markus

      Code:
      <input type="text" name="username" value="<?php echo @$_POST['username']; ?>" />
      why the symbol '@' here?? can you explain!

      Comment

      • sweetline priya
        New Member
        • Jan 2009
        • 16

        #4
        @Markus
        can u clarify one more doubt!! how to retain value for combo box???

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Originally posted by sweetline priya
          why the symbol '@' here?? can you explain!
          The '@' symbol simply suppresses an error - the error here being an 'undefined index' error. I would not recommend using it on just anything - we can be sure this error will not cause any failures, so we can escape it. We could use isset() to check for the variable, but that's more writing ;)

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Originally posted by sweetline priya
            @Markus
            can u clarify one more doubt!! how to retain value for combo box???
            How are you generating your select element?

            Comment

            • sweetline priya
              New Member
              • Jan 2009
              • 16

              #7
              Originally posted by Markus
              How are you generating your select element?
              i am using following coding to retrieve data from database...

              [code=php]
              $sql=mysql_quer y("SELECT system_type FROM systemtype ",$con);
              for($i = 0; $i < mysql_num_rows( $sql ); $i++)
              {
              $tmp = mysql_fetch_row ( $sql );
              print("<OPTION value=\"$tmp[0]\">$tmp[0]</OPTION>\n");
              }[/code]
              Last edited by Atli; Feb 18 '09, 02:22 PM. Reason: Added [code] tags.

              Comment

              • Markus
                Recognized Expert Expert
                • Jun 2007
                • 6092

                #8
                Originally posted by sweetline priya
                i am using following coding to retrieve data from database...


                $sql=mysql_quer y("SELECT system_type FROM systemtype ",$con);
                for($i = 0; $i < mysql_num_rows( $sql ); $i++)
                {
                $tmp = mysql_fetch_row ( $sql );
                print("<OPTION value=\"$tmp[0]\">$tmp[0]</OPTION>\n");
                }
                Is this a multi select or single select?

                Comment

                • sweetline priya
                  New Member
                  • Jan 2009
                  • 16

                  #9
                  @Markus

                  its a single select only..

                  Comment

                  • Markus
                    Recognized Expert Expert
                    • Jun 2007
                    • 6092

                    #10
                    Have a look at this thread. See what you can learn from that, and then post what you've tried.

                    - Markus.

                    Comment

                    Working...