473,770 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validating form input data

Hello everyone,

I am tying to come up with an elegant way to process some input data that
come from a form. When the user hits the 'Submit' button, i want the form to
appear again with the already entered valid data filled in and prompt the
user to re-enter the non-valid data. If all data is valid, i will forward to
an other .php page which enters the data into a database.

I tried to do this in the following way: the form always hits back on
itself, but when all data is valid i use the PHP:header() to redirect to the
data.php that performs the database insertion. The problem is that the data
is not available to data.php in the $_POST variable. How can i overcome this
problem? Any other subtle way to handle the whole thing? Any help
appreciated.
Apr 30 '06
17 3862
"Jerry Stuckle" <js*******@attg lobal.net> wrote in message
news:85******** ************@co mcast.com...
stathis gotsis wrote:
Hello everyone,

I am tying to come up with an elegant way to process some input data that come from a form. When the user hits the 'Submit' button, i want the form to appear again with the already entered valid data filled in and prompt the user to re-enter the non-valid data. If all data is valid, i will forward to an other .php page which enters the data into a database.

I tried to do this in the following way: the form always hits back on
itself, but when all data is valid i use the PHP:header() to redirect to the data.php that performs the database insertion. The problem is that the data is not available to data.php in the $_POST variable. How can i overcome this problem? Any other subtle way to handle the whole thing? Any help
appreciated.
Stathis,

I do things the same way you do - the page validates its own input and

then uses header() to move to the next page. But before the header() call, I store the data in the $_SESSION variable.

I prefer validating the data in the same page that contains the data. It keeps the code together and, IMHO, cleaner. Plus, if it isn't needed in the next page, you don't even have to touch that page.


Thank you for your answer. I missed the obvious: passing data through the
SESSION object on to the next page. This solution might even be more concise
than the MVC architecture that David suggested earlier on.
Apr 30 '06 #11
stathis gotsis wrote:
"Jerry Stuckle" <js*******@attg lobal.net> wrote in message
news:85******** ************@co mcast.com...
stathis gotsis wrote:
Hello everyone,

I am tying to come up with an elegant way to process some input data that come from a form. When the user hits the 'Submit' button, i want the form to appear again with the already entered valid data filled in and prompt the user to re-enter the non-valid data. If all data is valid, i will forward to an other .php page which enters the data into a database.

I tried to do this in the following way: the form always hits back on
itself, but when all data is valid i use the PHP:header() to redirect to the data.php that performs the database insertion. The problem is that the data is not available to data.php in the $_POST variable. How can i overcome this problem? Any other subtle way to handle the whole thing? Any help
appreciated.

Stathis,

I do things the same way you do - the page validates its own input and

then uses
header() to move to the next page. But before the header() call, I store

the
data in the $_SESSION variable.

I prefer validating the data in the same page that contains the data. It

keeps
the code together and, IMHO, cleaner. Plus, if it isn't needed in the

next
page, you don't even have to touch that page.


Thank you for your answer. I missed the obvious: passing data through the
SESSION object on to the next page. This solution might even be more concise
than the MVC architecture that David suggested earlier on.

It is more concise but suffers from marrying the view to the business
logic. If you want to update the view, say for supporting cell phones or
separating web page creation from the business logic, then it is easier
under MVC than in a monolithic form.

Both work. Which is best for you depends upon your needs.

One thing I like about MVC is that the controllers and view all follow
the same general format which makes understanding a new page easier.

Controllers condition their environment, handle any POST/GET data, set
the SESSION and redirect.

Views bring in any SESSION data, set up for internationaliz ation and
paint the form.

Obviously, you can combine the controller and view into one page. I find
that the resulting pages can get to be quite large (lines of code) and
complex (lots of business logic) which gets in the way on understanding
how the page is being defined (i.e. the HTML)

-david-

Apr 30 '06 #12
Hello,

on 04/30/2006 12:17 PM Jerry Stuckle said the following:
I am tying to come up with an elegant way to process some input data
that
come from a form. When the user hits the 'Submit' button, i want the
form to
appear again with the already entered valid data filled in and prompt
the
user to re-enter the non-valid data. If all data is valid, i will
forward to
an other .php page which enters the data into a database.

I tried to do this in the following way: the form always hits back on
itself, but when all data is valid i use the PHP:header() to redirect
to the
data.php that performs the database insertion. The problem is that
the data
is not available to data.php in the $_POST variable. How can i
overcome this
problem? Any other subtle way to handle the whole thing? Any help
appreciated.

Nothing stops you from presenting the form and process it with the same
script.

You may want to take a look at this forms generation and validation
class that shows you how to do that. Additionally it generates your
forms with Javascript to validate the form also on the client site,
avoiding unnecessary server round trips just to tell the user the form
has invalid fields.

http://www.phpclasses.org/formsgeneration


And what happens if someone has javascript turned off?

NEVER rely on client side validation!

This is a very mature class. It implements server side validation since
when it was released for the first time in 1999 . It generates client
side validation Javascript code to reduce server needless round trips
and so improve user-friendliness.
--

Regards,
Manuel Lemos

Metastorage - Data object relational mapping layer generator
http://www.metastorage.net/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
Apr 30 '06 #13
"David Haynes" <da***********@ sympatico.ca> wrote in message
news:o9******** *********@fe69. usenetserver.co m...
It is more concise but suffers from marrying the view to the business
logic. If you want to update the view, say for supporting cell phones or
separating web page creation from the business logic, then it is easier
under MVC than in a monolithic form.
Yes, that is true. If that is the case, i assume the controller will
redirect to the appropriate view suited to the client's equipment (or rather
browser), am i right?
Both work. Which is best for you depends upon your needs.

One thing I like about MVC is that the controllers and view all follow
the same general format which makes understanding a new page easier.

Controllers condition their environment, handle any POST/GET data, set
the SESSION and redirect.
In your original post you implied that the controller can also contain
insert/update (into database) actions. Should the controller redirect to
another page that handles this stuff? It does not really matter in the
situation i am involved in right now, but i want to stick to correct
guidelines.
Views bring in any SESSION data, set up for internationaliz ation and
paint the form.

Obviously, you can combine the controller and view into one page. I find
that the resulting pages can get to be quite large (lines of code) and
complex (lots of business logic) which gets in the way on understanding
how the page is being defined (i.e. the HTML)


What i did was combine some of the controller's logic into the the form's
page. If alla data is valid the user gets redirected to another page which
handles database actions. I did this because i found passing around data
through the SESSION variable a bit clumsy. However, i can see the advantages
of the MVC model you suggest. Thank you again for the detailed explanation.
May 1 '06 #14
stathis gotsis wrote:
"David Haynes" <da***********@ sympatico.ca> wrote in message
news:o9******** *********@fe69. usenetserver.co m...
It is more concise but suffers from marrying the view to the business
logic. If you want to update the view, say for supporting cell phones or
separating web page creation from the business logic, then it is easier
under MVC than in a monolithic form.
Yes, that is true. If that is the case, i assume the controller will
redirect to the appropriate view suited to the client's equipment (or rather
browser), am i right?


Whatever is appropriate. My controllers know about cell phones, PDAs and
browsers and will redirect to the correct form as needed.
Both work. Which is best for you depends upon your needs.

One thing I like about MVC is that the controllers and view all follow
the same general format which makes understanding a new page easier.

Controllers condition their environment, handle any POST/GET data, set
the SESSION and redirect.


In your original post you implied that the controller can also contain
insert/update (into database) actions. Should the controller redirect to
another page that handles this stuff? It does not really matter in the
situation i am involved in right now, but i want to stick to correct
guidelines.


I don't do another redirect. I encapsulate the database access into a
set of classes (all based upon a master database access object). My
class is sort of like Hibernate in that it treats the database as a
reliable object store albeit without the overhead of serialization.

I have other classes to assist the business logic that present more
complex database views.

In my case, let's say I have a table called ACCOUNT. I will have an
object that subclasses the master database object and implements an
Account object. The instance may then be used to access a single row or
to provide a set of rows from the ACCOUNT table. Additionally, the
getter and setter routines are implemented as $foo = $account->login;
and $account->login = 'foo'; which is a lot easier than writing all
those getLogin() and setLogin() methods.
Views bring in any SESSION data, set up for internationaliz ation and
paint the form.

Obviously, you can combine the controller and view into one page. I find
that the resulting pages can get to be quite large (lines of code) and
complex (lots of business logic) which gets in the way on understanding
how the page is being defined (i.e. the HTML)


What i did was combine some of the controller's logic into the the form's
page. If alla data is valid the user gets redirected to another page which
handles database actions. I did this because i found passing around data
through the SESSION variable a bit clumsy. However, i can see the advantages
of the MVC model you suggest. Thank you again for the detailed explanation.


It can be a pain to load and unload the SESSION but if you are playing
in multiple interfaces - as I am - it can really save you a lot of time.
Also, think of the data passing from the controllers and views as your
API definition. You have a very well defined set of data that the
controller will accept and a well defined set of data that the view will
accept. This can make data verification/validation a lot easier.

Good luck with your project.

-david-

May 1 '06 #15
Warning OT>>>

is it only me- or is that phpclassess.org a little on the bizarres
side?

I had to download google-analytical.com/ tribalfusion.co m, a visual
basic mpg ad of a guy mixing coffee grounds and water in his mouth to
get to the links for the examples. Only to then find I have to pick a
mirror, register/ login..''

Note to self: Don't bother trying to view anything at phpclasses.org
ever again.

</rant>

May 1 '06 #16
Warning OT>>>

is it only me- or is that phpclassess.org a little on the bizarres
side?

I had to download google-analytical.com/ tribalfusion.co m, a visual
basic mpg ad of a guy mixing coffee grounds and water in his mouth to
get to the links for the examples. Only to then find I have to pick a
mirror, register/ login... but alas I forgot what the hell I was doing
and moved along the net else where. wtf.

Note to self: Don't bother trying to view anything at phpclasses.org
ever again.

</rant>

May 1 '06 #17
Hello,

on 05/01/2006 06:11 AM sp************* *@comcast.net said the following:
Warning OT>>>

is it only me- or is that phpclassess.org a little on the bizarres
side?

I had to download google-analytical.com/ tribalfusion.co m, a visual
basic mpg ad of a guy mixing coffee grounds and water in his mouth to
I don't know what you do for a living but the PHPClasses site depends on
advertising revenue to keep open.

get to the links for the examples. Only to then find I have to pick a
mirror, register/ login..''
This is often a misundestood matter. You may want to read this to
understand why.

http://www.phpclasses.org/faq/#subscribe-to-download

BTW, when you are subscribed and logged, you are not redirected to a mirror.

Note to self: Don't bother trying to view anything at phpclasses.org
ever again.

</rant>


Since you work with PHP I suspect that Google will point you to this
site very often. After all, from the about 10,000 users that subscribe
to the site every month, great part of them are lead by Google.
--

Regards,
Manuel Lemos

Metastorage - Data object relational mapping layer generator
http://www.metastorage.net/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
May 1 '06 #18

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

Similar topics

5
2894
by: The Plankmeister | last post by:
Hi... What's the best method of validating input characters? I would like to prevent users submitting exotic characters (such as those acquired on Windows Systems by pressing ALT+) and thought a way of doing this would be to compare the submitted strings with the array keys returned by get_html_translation_table(HTML_ENTITIES), but padding this array out with all the remaining normal keyboard characters. But... am I reinventing the...
3
14021
by: Mark | last post by:
Hi, Im trying to validate a form, all the validating works apart from one field. This particular field must consist of the first 2 characters as letters, & the following 5 as numbers. And if it dosent meet these requirments an error message will be displayed. I have pasted the code (and highlighted the relevant parts) below in the hope that someone can help me out with this. Ive been trying to suss it out all week & it's driving me nuts!...
0
1609
by: Bradley Bossard via DotNetMonster.com | last post by:
I am having an issue with the .NET framework (or C#) and validating events. I have implemented several validating event handlers for textboxes on a form. When I run the app, the form works correctly the first time, but if I input some data in the form and click another control to change focus, the validator fires, but if I continue to hit 'ESC' enough times, it eventually lets me out of the validating loop and moves focus to the other...
2
1348
by: Osmosis | last post by:
I have a form with several controls, which all have their validating and validated events in my code. However, if these controls don't get focus, these events don't get called. When my OK button is pressed, I need all the controls to be validated. How can I get this done ? Do I have to call the events individually for each control, and if so, how do I do this ?
0
2440
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852 (http://support.microsoft.com/kb/810852), but then I realized that the hotfix mentioned was in .Net v1.1, which I am using. I took the sample from that article and recreated the situation I see in my application. (Code included below.) If you run the...
9
5845
by: chuck | last post by:
I need some help with validating user input. I am writing a C computer program for an intro to C course. Here is the situation. I am creating an application that will do currency conversions. The user will be presented with a list of 5 selections they can make. They will then be prompted for which selection they want to enter (which can only be 1-5, no characters or anything like it). Once they select the number, 1 for Euro, 2 for...
4
2481
by: easoftware | last post by:
I am using VS .Net 2003 and VB. I have an app with one parent and two Mdi child forms. I need to validate data in the Mdi form. The Form.Validating event works when I try to close a Mdi form, but not when I try to switch form one Mdi form to the other. I tried to add code to MdiForm1's Deactivate event: Private Sub MidForm1_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Deactivate Dim TempE As...
2
1492
by: MadMike42 | last post by:
This is really starting to annoy me, I've got a form, that has some input boxes, a example of the code is here:- <form action="admin_save_stock.asp" method="post" name="MyFormData"> <input name="Make" type="text" id="MenuText" value=<% response.write rsTable("Make") %size="50" maxlength="50"> <input name="DateBought" id="MenuText" type="text" value=<% response.write rsTable("DateBought") % size="10" maxlength="10"> </form>
0
9617
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9453
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8929
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5481
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.