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

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-11-2003
william c
 
Posts: n/a
Default 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
Reply With Quote
  #2 (permalink)  
Old 09-12-2003
Keiron Waites
 
Posts: n/a
Default 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.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...
}
?>


Reply With Quote
  #3 (permalink)  
Old 09-12-2003
Gary Petersen
 
Posts: n/a
Default 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.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

Reply With Quote
  #4 (permalink)  
Old 09-12-2003
william c
 
Posts: n/a
Default Re: Is there a way to treat a PHP page like a form?



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!
Reply With Quote
  #5 (permalink)  
Old 09-12-2003
william c
 
Posts: n/a
Default Re: Is there a way to treat a PHP page like a form?



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
Reply With Quote
  #6 (permalink)  
Old 09-12-2003
Geoff Berrow
 
Posts: n/a
Default Re: Is there a way to treat a PHP page like a form?

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/
Reply With Quote
  #7 (permalink)  
Old 09-12-2003
Martin Lucas-Smith
 
Posts: n/a
Default 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.19347955@williamc.com> with its hoof:

>
> <chuckle />


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



Martin

Reply With Quote
  #8 (permalink)  
Old 09-12-2003
Andy Jeffries
 
Posts: n/a
Default 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:
>> > 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
Reply With Quote
  #9 (permalink)  
Old 09-12-2003
Geoff Berrow
 
Posts: n/a
Default 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.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/
Reply With Quote
  #10 (permalink)  
Old 09-12-2003
Michael W. Cocke
 
Posts: n/a
Default 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:

>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 =---
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:16 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0