This is a discussion on Is there a way to treat a PHP page like a form? within the PHP Language forums, part of the PHP Programming Forums category; I don't really know PHP that well. I'm fixing a Perl program that accesses a db after getting ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
"william c" <temp4_NO_SPAM_@williamc.com> wrote in message news:3F60DC5E.19347955@williamc.com... > > 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. > [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... } ?> |
|
|||
|
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.19347955@williamc.com> with its hoof: > 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 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="$_SESSION[saved][username]" > ... PHPRULZ; HTH |
|
|||
|
Keiron Waites wrote: > 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: > thanks! |
|
|||
|
Gary Petersen wrote: > > 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.19347955@williamc.com> with its hoof: <chuckle /> > 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: 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 |
|
|||
|
Message-ID: <3F61A588.46416177@williamc.com> from william c contained the
following: >I have the O'Reilly PHP book, I guess I >should read it. 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/ |
|
|||
|
> > 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.19347955@williamc.com> with its hoof: > > <chuckle /> <off-topic>How are these generated, btw?</off-topic> Martin |
|
|||
|
On Fri, 12 Sep 2003 13:23:42 +0100, Martin Lucas-Smith wrote:
>> > 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.19347955@williamc.com> with its hoof: >> >> <chuckle /> > > <off-topic>How are these generated, btw?</off-topic> By using a decent newsreader (Pan is one of the most-compliant around). Cheers, Andy |
|
|||
|
Good Grief! Was it really true that Message-ID:
<pan.2003.09.12.12.47.49.324304@andyjeffries.remov e.co.uk> from Andy Jeffries contained the following: >> <off-topic>How are these generated, btw?</off-topic> > >By using a decent newsreader (Pan is one of the most-compliant around). 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/ |
|
|||
|
On Fri, 12 Sep 2003 16:00:57 +0100, Geoff Berrow <$bl$@ckdog.co.uk>
wrote: >Good Grief! Was it really true that Message-ID: ><pan.2003.09.12.12.47.49.324304@andyjeffries.remo ve.co.uk> from Andy >Jeffries contained the following: > >>> <off-topic>How are these generated, btw?</off-topic> >> >>By using a decent newsreader (Pan is one of the most-compliant around). > >Agent will do that too for windoze users. 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 =--- |