Is there a way to treat a PHP page like a form?

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

    Is there a way to treat a PHP page like a form?


    I don't really know PHP that well.

    I'm fixing a Perl program that accesses a db after getting form input
    from a PHP page. If the server-side validation fails I'd like to reload
    the form with all the user's info still filled in.

    I could embed the entire page in the Perl program but it seems like
    there must be a better way to go. Is there a way to get the info into
    the Post environment variable and add code for the PHP page to read it
    from there?

    thx,

    --williamc
  • Keiron Waites

    #2
    Re: Is there a way to treat a PHP page like a form?


    "william c" <temp4_NO_SPAM_ @williamc.com> wrote in message
    news:3F60DC5E.1 9347955@william c.com...[color=blue]
    >
    > I don't really know PHP that well.
    >
    > I'm fixing a Perl program that accesses a db after getting form input
    > from a PHP page. If the server-side validation fails I'd like to reload
    > the form with all the user's info still filled in.
    >[/color]
    [snip]

    Do this with your form elements:

    <input type="text" name="name" value="<?php print $_POST['name']; ?>">

    On first load of the page, check to see if the form has been submitted and
    if it hasn't create the values so that no errors are encountered:

    <?php
    if (!isset($_POST['name'])) {
    $_POST['name'] = "";
    etc...
    }
    ?>


    Comment

    • Gary Petersen

      #3
      Re: Is there a way to treat a PHP page like a form?

      A horsie named william c demonstrated surprising intelligence and its
      ability to use morse code on Thu, 11 Sep 2003 15:36:11 -0500 when it
      tapped <3F60DC5E.19347 955@williamc.co m> with its hoof:

      [color=blue]
      > I don't really know PHP that well.
      >
      > I'm fixing a Perl program that accesses a db after getting form input
      > from a PHP page. If the server-side validation fails I'd like to reload
      > the form with all the user's info still filled in.
      >
      > I could embed the entire page in the Perl program but it seems like
      > there must be a better way to go. Is there a way to get the info into
      > the Post environment variable and add code for the PHP page to read it
      > from there?
      >
      > thx,
      >
      > --williamc[/color]

      When the validation fails, save the POST data into a
      session variable and redirect to the form page.
      When the form page loads, put the
      saved post data into the form elements:

      validate.php:
      if (authfailed()) {
      $_SESSION['saved'] = $_POST;
      // Warning: The following assumes the session cookie
      // is available.
      header ("Location: http://mysite.com/form.php");
      exit();
      }


      form.php:
      echo <<<PHPRULZ
      <form ...>
      <input type=text name='username'
      value="$_SESSIO N[saved][username]" >
      ...
      PHPRULZ;

      HTH

      Comment

      • william c

        #4
        Re: Is there a way to treat a PHP page like a form?



        Keiron Waites wrote:
        [color=blue]
        > Do this with your form elements:
        >
        > <input type="text" name="name" value="<?php print $_POST['name']; ?>">
        >
        > On first load of the page, check to see if the form has been submitted and
        > if it hasn't create the values so that no errors are encountered:
        >[/color]

        thanks!

        Comment

        • william c

          #5
          Re: Is there a way to treat a PHP page like a form?



          Gary Petersen wrote:[color=blue]
          >
          > A horsie named william c demonstrated surprising intelligence and its
          > ability to use morse code on Thu, 11 Sep 2003 15:36:11 -0500 when it
          > tapped <3F60DC5E.19347 955@williamc.co m> with its hoof:[/color]

          <chuckle />
          [color=blue]
          > When the validation fails, save the POST data into a
          > session variable and redirect to the form page.
          > When the form page loads, put the
          > saved post data into the form elements:[/color]

          Ok, thinking out load here... Does this make sense? Currently this page
          uses javascript to validate and after it validates, submits to the Perl
          program. Normally, when it validates on the client side it validates on
          the server side, too. But it could fail if the Perl code strips out a
          lot of evil characters (not that I care about making it convenient to
          re-enter in that case) or if the user has js turned off.

          If I move the data checking and cleansing out of the Perl and into a PHP
          function, since it's happening on the server, that should be as reliable
          as doing it in the cgi. Only after it gets past the PHP validation
          function do I submit it to the Perl. Then, the Perl should fail only if
          the insert into the db etc. fails, in which case I'm probably screwed
          anyway...

          So maybe that's what I should do, and not even use a session. And maybe
          rewrite everything to use just PHP to validate, make the connection to
          the db, insert the data etc... I have the O'Reilly PHP book, I guess I
          should read it.

          thx for the help,

          williamc

          Comment

          • Geoff Berrow

            #6
            Re: Is there a way to treat a PHP page like a form?

            Message-ID: <3F61A588.46416 177@williamc.co m> from william c contained the
            following:
            [color=blue]
            >I have the O'Reilly PHP book, I guess I
            >should read it.[/color]

            Nah... just do it.

            --
            Geoff Berrow
            It's only Usenet, no one dies.
            My opinions, not the committee's, mine.
            Simple RFDs http://www.ckdog.co.uk/rfdmaker/

            Comment

            • Martin Lucas-Smith

              #7
              Re: Is there a way to treat a PHP page like a form?


              [color=blue][color=green]
              > > A horsie named william c demonstrated surprising intelligence and its
              > > ability to use morse code on Thu, 11 Sep 2003 15:36:11 -0500 when it
              > > tapped <3F60DC5E.19347 955@williamc.co m> with its hoof:[/color]
              >
              > <chuckle />[/color]

              <off-topic>How are these generated, btw?</off-topic>



              Martin

              Comment

              • Andy Jeffries

                #8
                Re: Is there a way to treat a PHP page like a form?

                On Fri, 12 Sep 2003 13:23:42 +0100, Martin Lucas-Smith wrote:[color=blue][color=green][color=darkred]
                >> > A horsie named william c demonstrated surprising intelligence and its
                >> > ability to use morse code on Thu, 11 Sep 2003 15:36:11 -0500 when it
                >> > tapped <3F60DC5E.19347 955@williamc.co m> with its hoof:[/color]
                >>
                >> <chuckle />[/color]
                >
                > <off-topic>How are these generated, btw?</off-topic>[/color]

                By using a decent newsreader (Pan is one of the most-compliant around).

                Cheers,


                Andy

                Comment

                • Geoff Berrow

                  #9
                  Re: Is there a way to treat a PHP page like a form?

                  Good Grief! Was it really true that Message-ID:
                  <pan.2003.09.12 .12.47.49.32430 4@andyjeffries. remove.co.uk> from Andy
                  Jeffries contained the following:
                  [color=blue][color=green]
                  >> <off-topic>How are these generated, btw?</off-topic>[/color]
                  >
                  >By using a decent newsreader (Pan is one of the most-compliant around).[/color]

                  Agent will do that too for windoze users.

                  --
                  Geoff Berrow
                  It's only Usenet, no one dies.
                  My opinions, not the committee's, mine.
                  Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                  Comment

                  • Michael W. Cocke

                    #10
                    Re: Is there a way to treat a PHP page like a form?

                    On Fri, 12 Sep 2003 16:00:57 +0100, Geoff Berrow <$bl$@ckdog.co. uk>
                    wrote:
                    [color=blue]
                    >Good Grief! Was it really true that Message-ID:
                    ><pan.2003.09.1 2.12.47.49.3243 04@andyjeffries .remove.co.uk> from Andy
                    >Jeffries contained the following:
                    >[color=green][color=darkred]
                    >>> <off-topic>How are these generated, btw?</off-topic>[/color]
                    >>
                    >>By using a decent newsreader (Pan is one of the most-compliant around).[/color]
                    >
                    >Agent will do that too for windoze users.[/color]

                    Agent will do it for linux users too - works fine under wine.

                    Mike-
                    Mornings: Evolution in action. Only the grumpy will survive.
                    -----------------------------------------------------

                    Please note - Due to the intense volume of spam, we have
                    installed site-wide spam filters at catherders.com. If
                    email from you bounces, try non-HTML, non-encoded,
                    non-attachments.


                    ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
                    http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
                    ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---

                    Comment

                    Working...