473,385 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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
Jul 16 '05 #1
9 2685

"william c" <te************@williamc.com> wrote in message
news:3F***************@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...
}
?>
Jul 16 '05 #2
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 <3F***************@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

Jul 16 '05 #3


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!
Jul 16 '05 #4


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 <3F***************@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
Jul 16 '05 #5
Message-ID: <3F***************@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/
Jul 16 '05 #6

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 <3F***************@williamc.com> with its hoof:


<chuckle />


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

Martin

Jul 16 '05 #7
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 <3F***************@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
Jul 16 '05 #8
Good Grief! Was it really true that Message-ID:
<pa****************************@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/
Jul 16 '05 #9
On Fri, 12 Sep 2003 16:00:57 +0100, Geoff Berrow <$b**@ckdog.co.uk>
wrote:
Good Grief! Was it really true that Message-ID:
<pa****************************@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 =---
Jul 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Xamle Eng | last post by:
One of the things I find most unnatural about most XML APIs is that they try to abstract both elements and text into some kind of "node" object when they have virtually nothing in common. The...
7
by: Steven T. Hatton | last post by:
"Reduced subclassing. Factory Method (107) often produces a hierarchy of Creator classes that parallels the product class hierarchy. The Prototype pattern lets you clone a prototype instead of...
11
by: Jeevan | last post by:
Hi, I have some data which I am getting from a socket. I am currently storing the data in an array (so that future reading of the data will be fast as it will be in RAM instead of hard disk)....
2
by: John Lau | last post by:
Hi, Is there documentation that talks about the page lifecycle, the lifecycle of controls on the page, and the rendering of inline code, in a single document? Thanks, John
3
by: farmer | last post by:
<%@ Page Language="C#" Debug="true"%> <SCRIPT language="C#" runat="server"> void Alt(Object From,EventArgs aEventArgs){ Info.Text=((LinkButton)From).Text; } </script> <HTML> <BODY> <form...
7
by: Wanjun Yu | last post by:
Hi All, On my windows form, when the user hits the return key, I'll need to treat it as a tab key. i.e. when the user hits a return, the focus will move to the next item in the tab-order on the...
1
by: mark4asp | last post by:
Is it possible to treat values and items of a DropDownList like a HashTable? My page records the value of the ConsultantName in a label lblConsultant and the ID in a hidden field hidConsultantID...
2
by: rdemarco | last post by:
Hi guys I'm trying to use the eval() function to run code that I have previously compiled via string concatenation. Some of it works, for example, I can set the focus to a combo box called...
7
tdw
by: tdw | last post by:
Hi all, I've tried to find this answer in the help menu and online but haven't found it: When I type in a field on my form, and then hit backspace to erase what I just typed, my understanding...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.