Passing variables

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

    Passing variables

    I allows users to enter data in a form. I process the form with a php file.
    I return control to another page on my website. I want to dynamical create
    the page that they are returned to so I can show them a copy of what they
    just entered. I cant get the syntax of this. My host is set to globals on
    and php 4.

    Example
    Form

    <FORM method="post" action="process _this.php" name="anmals" id="anmals" >
    <TABLE width="400" BORDER="2" CELLSPACING="0" cellpadding="4" >
    <td >Name</td>
    <td ><input type="text" size="45" name="realname" value= ""></td>
    </TABLE>
    </FORM>

    process_this.ph p
    $realname=$_POS T['realname'];
    Header("Locatio n: index5c.html")

    On index5c.html I want to use $realname to display the data the user entered
    on the form. There is something I am missing here as I am getting "null"
    back. I have tried various combinations of commands which I wont go into
    here. Can someone explain how I can pass the user data to index5c.html and
    display it.

    Garry Jones
    Sweden


  • Areric

    #2
    Re: Passing variables

    what is the motivation behind using the index5c.html page. Generally
    you display your content on the same page you submit to.

    Also you cannot use a header() call if anything has already been
    output.

    In your example $realname is a variable local only to the
    process_this.ph p file. When you call header() you redirect the user to
    index5c.html which has no access to the $realname variable.

    Comment

    • Locu

      #3
      Re: Passing variables

      Your problem is that it is process_this.ph p that has the form post
      information, when you do the header request to forward to index5c.html
      it's just like loading a fresh page with no post data.

      To get around that, i'd use a session.
      For example:
      on both process_this.ph p and index5c.html put at the very top:
      session_start() ;

      Now in process_this.ph p put:
      $_SESSION['realname'] = $_POST['realname'];

      Then in index5c.html you can directly reference the session variable or
      assign it and use it in your html:
      <html>
      Hello <?php echo $_SESSION['realname'] ?>.
      </html>

      Comment

      • Areric

        #4
        Re: Passing variables

        i assume you have your web server set up to parse html files in php.
        Most servers interpret html as normal files to send flat out to the
        browser and php files are interpreted and then sent.

        Just be careful about that, otherwise your session wont work and itll
        actually display session_start() ; to the user.

        Comment

        • fletch

          #5
          Re: Passing variables

          Why not post the form to index5c.html?

          Does process_this.ph p do anything else?

          Comment

          • Garry Jones

            #6
            Re: Passing variables

            "Areric" <josh.schramm@g mail.com> skrev i meddelandet
            news:1144859265 .824519.146700@ z34g2000cwc.goo glegroups.com.. .[color=blue]
            > what is the motivation behind using the index5c.html page. Generally
            > you display your content on the same page you submit to.[/color]

            Ok, maybe I am not going about this in the best way. Lets start from the
            begining.

            I have a page in which users can enter data about themselves and their
            friends to sign up for a sporting event. I process the form and the MySQL
            coding with process_this.ph p. I then return control to the index5c.html
            which thanks the user for his registration(s) . Here, I thought would be a
            good idea to remind the user of the data that has been keyed in. Based on
            how many participants the user has registered and according to which
            distance for each participant is signed up for the total price will be
            different. That will all come later first I need to be able to pass
            variables back.

            However, a thought struck me. Maybe its best not to process the SQL coding
            straight away. When the user clicks submit maybe I can use a preview page
            which shows the user the data entered and asks him to confirm the
            registration. Here I could also use some maths to show him the ammount of
            money to pay in if he confirms. Cancel would send the user back to the entry
            form, OK would submit and send to a process php file which would handle the
            code for MySQL.

            So, starting like this...

            <FORM method="post" action="preview _this.php" name="anmals" id="anmals" >
            <TABLE width="400" BORDER="2" CELLSPACING="0" cellpadding="4" >
            <td >Name</td>
            <td ><input type="text" size="45" name="realname" value= ""></td>
            </TABLE>
            </FORM>

            I need to create a preview page. In this preview I need to show $realname
            and be able to do some calculations on other variables before displaying the
            data. I'd like to show a new form with no user editable information, the
            user reads it, sees the ammount payable and clicks OK or Cancel. OK sends it
            off to the process_this.ph p

            Can someone point me in the right direction to set this up.

            Garry Jones
            Sweden






            Comment

            • Jerry Stuckle

              #7
              Re: Passing variables

              Garry Jones wrote:[color=blue]
              > "Areric" <josh.schramm@g mail.com> skrev i meddelandet
              > news:1144859265 .824519.146700@ z34g2000cwc.goo glegroups.com.. .
              >[color=green]
              >>what is the motivation behind using the index5c.html page. Generally
              >>you display your content on the same page you submit to.[/color]
              >
              >
              > Ok, maybe I am not going about this in the best way. Lets start from the
              > begining.
              >
              > I have a page in which users can enter data about themselves and their
              > friends to sign up for a sporting event. I process the form and the MySQL
              > coding with process_this.ph p. I then return control to the index5c.html
              > which thanks the user for his registration(s) . Here, I thought would be a
              > good idea to remind the user of the data that has been keyed in. Based on
              > how many participants the user has registered and according to which
              > distance for each participant is signed up for the total price will be
              > different. That will all come later first I need to be able to pass
              > variables back.
              >
              > However, a thought struck me. Maybe its best not to process the SQL coding
              > straight away. When the user clicks submit maybe I can use a preview page
              > which shows the user the data entered and asks him to confirm the
              > registration. Here I could also use some maths to show him the ammount of
              > money to pay in if he confirms. Cancel would send the user back to the entry
              > form, OK would submit and send to a process php file which would handle the
              > code for MySQL.
              >
              > So, starting like this...
              >
              > <FORM method="post" action="preview _this.php" name="anmals" id="anmals" >
              > <TABLE width="400" BORDER="2" CELLSPACING="0" cellpadding="4" >
              > <td >Name</td>
              > <td ><input type="text" size="45" name="realname" value= ""></td>
              > </TABLE>
              > </FORM>
              >
              > I need to create a preview page. In this preview I need to show $realname
              > and be able to do some calculations on other variables before displaying the
              > data. I'd like to show a new form with no user editable information, the
              > user reads it, sees the ammount payable and clicks OK or Cancel. OK sends it
              > off to the process_this.ph p
              >
              > Can someone point me in the right direction to set this up.
              >
              > Garry Jones
              > Sweden
              >
              >
              >
              >
              >
              >[/color]
              You can use hidden fields or sessions to pass the data. If data security is a
              concern, I recommend sessions.

              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              • fletch

                #8
                Re: Passing variables

                Personally I would have all this on one page. There is a lot of
                duplication involved.

                To do it your way you need to pass variables between pages. There are a
                number of ways to do this.

                1) Session
                2) Get str
                3) Cookie.

                Session - good for large amount of data, and stored on server.
                Get - good for limited amount of data, if the string makes sense by
                itself then the page can be bookmarked,
                Cookie - I think you may as well use a session but they do occasionally
                have their uses.

                We also find putting a timestamp on form posts and values to be useful.
                What happens if the same user sends a form twice, by going back in the
                browser or pressing refresh? Do they get registered twice. Store the
                form in the session using the timestamp created in a hidden field in
                the form. Check the timestamps as they come in, and the form name
                against previous forms to do an array_equals(). If you find you've got
                exactly the same thing then you have a duplicate post, if not then you
                have to process the form as normal.

                Comment

                • Garry Jones

                  #9
                  Re: Passing variables

                  "Jerry Stuckle" <jstucklex@attg lobal.net> skrev i meddelandet
                  news:CJidnTeYFO KIV6DZRVn-pw@comcast.com. ..
                  [color=blue]
                  > You can use hidden fields or sessions to pass the data. If data security
                  > is a concern, I recommend sessions.[/color]

                  I found the readonly tag of the input field. I can now pass variables around
                  and set an identical same form to readonly. By php include I should be able
                  to turn readonly off or on according to it being the preview form or data
                  entry form. I am now testing and it is starting to take shape

                  Garry Jones
                  Sweden






                  Comment

                  Working...