8 Replies Latest reply on Jul 16, 2011 3:22 PM by Sheryl909

    How do I get a value from an element to variable?

    Sheryl909

      I have a simple page with name and address text fields on a form.

       

      Last name:   (txtLastName)

      First name:   (txtFirstName)

      Address:      (txtAddress1)

      etc....

       

      After the user enters information, what is the syntax to get this information into a form variable?  I want the variables available on the next page.

       

      $varLastName = ['txtLastName'];  ?

       

      Thanks.

       

      PS  I am obviously a newby, and am very frustrated.  I'd really appreciate your help!

        • 1. Re: How do I get a value from an element to variable?
          MurraySummers Level 8

          Those values will be in the posted data.  Can you not parse it from the data?

           

          Pehaps if you said more about what you are doing and why you want this it would help us answer.  Also, a look at your form would help too - can you post a link?

          • 2. Re: How do I get a value from an element to variable?
            MurraySummers Level 8

            Last name:   (txtLastName)

            First name:   (txtFirstName)

            Address:      (txtAddress1)

            etc....

             

            After the user enters information, what is the syntax to get this information into a form variable?  I want the variables available on the next page.

             

            $varLastName = ['txtLastName'];  ?

             

            Oh, perhaps we have enough....

             

            On the page to which the form submits, do this -

             

            <?php $varLastName = $_POST['txtLastName']; ?>

             

            You might also want to process that posted data to remove any bad characters, like -

             

            $varLastName = trim(strip_slashes($_POST['txtLastName']));

             

            Is that what you are looking for?

            • 3. Re: How do I get a value from an element to variable?
              Sheryl909 Level 1

              Thank you for your response.  I am trying to setup a user's data to be written to a database once I have all the information, which will come from more than one page.  Isn't that the best way to do it?  I had been writing data to the database using a Submit button as I went along, but what if they change their minds and don't want to pay for the service I'm offering?  Then I have data I don't need.  From what I've read, it seems that I should be using Session variables to store the data from one page to the next, but I don't know how to do that.

               

              Can I post data without it going into a database?

               

              I don't know how to post a link to my page.  I'm not up and running on a server yet.  My page is so simple.  It's a form with a table displaying labels and text boxes for last name, first name, address, city, state and zip.

              • 4. Re: How do I get a value from an element to variable?
                MurraySummers Level 8

                From what I've read, it seems that I should be using Session variables to store the data from one page to the next, but I don't know how to do that.

                 

                Google can help you here.  It's pretty simple.

                 

                Can I post data without it going into a database?

                 

                Sure - when you submit a form, it's posted to the next page in the header so that it's not visible to the user.

                 

                If you want to have multiple page forms, then each page can submit to each subsequent page, where the previous page's data is loaded into hidden fields.  That way, each page submits the full accumulated set of data.  Does that make sense?

                 

                <input type="hidden" value="<?php echo $_POST['whatever']; ?>" name="field1" id="field1">

                • 5. Re: How do I get a value from an element to variable?
                  Sheryl909 Level 1

                  Yes, this is more of what I'm looking for:

                   

                  <?php $varLastName = $_POST['txtLastName']; ?>

                   

                  I did already try this and I got errors.  Maybe I had the code in the wrong place.  Assuming I got it to work, where does the data go once it's posted?

                   

                  Let's say I want to put the variable into a text box.  What would be the

                  code for that?

                  • 6. Re: How do I get a value from an element to variable?
                    Sheryl909 Level 1

                    Yes, this is making more sense, but how do I access the variables that are

                    passed in order to post them?  I mean, what is the syntax?

                    • 7. Re: How do I get a value from an element to variable?
                      MurraySummers Level 8

                      Read my previous reply.  It's exactly that that I show - except that the text box is a hidden text field.

                      • 8. Re: How do I get a value from an element to variable?
                        Sheryl909 Level 1

                        Thank you so much for your help!