473,399 Members | 2,858 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,399 software developers and data experts.

forms + validation

Hi. I haven't written in PHP too much so I think I should ask how my
problem can be solved "the right way".

I'm having some forms (actually this is not my code, and actually I
haven't got it yet but I see the result). This forms should be filled by
user and when filled and when user clickes on the Next button the next
page or the same page with filled results and some yellow/red/whatever
signs that something was not filled is shown.

Now it doesn't do anything of that.

The first thing (showing previously typed values) is simple: I should
just put every field a value from $_POST, like <field value=<?php $_POST
["field"]>.

Now the second one would also be simple, smth like:

function showError(field) {
if (field == NULL)
print "some html element with yellow/red/whatever signs";
}

And now just add this showError() to every field.

But that is not enough because this is not a validation. And if I am to
add validation for every field I have to write as many showError()
functions as there are fields or write a huge switch statement inside
showError().

And if there are some checkboxes, radiobuttons and other select lists
then why should I write all this validation by hand? Maybe there is a way
to specify this validation in more simple way? Like saying that if $_POST
contains information about selection in some list then it should be
selected, and elesewhere it should validate automatically about selection
indices in list and so on.

Is it possible to do such things? Or maybe I should write my showError()
in Javascript instead? Or maybe I am wrong about the solution. What is
the "right way" of doing such things?
Sep 24 '07 #1
1 1434
On 24 sep, 16:23, Sergei Riaguzov <he...@world.comwrote:
Hi. I haven't written in PHP too much so I think I should ask how my
problem can be solved "the right way".

I'm having some forms (actually this is not my code, and actually I
haven't got it yet but I see the result). This forms should be filled by
user and when filled and when user clickes on the Next button the next
page or the same page with filled results and some yellow/red/whatever
signs that something was not filled is shown.

Now it doesn't do anything of that.

The first thing (showing previously typed values) is simple: I should
just put every field a value from $_POST, like <field value=<?php $_POST
["field"]>.

Now the second one would also be simple, smth like:

function showError(field) {
if (field == NULL)
print "some html element with yellow/red/whatever signs";

}

And now just add this showError() to every field.

But that is not enough because this is not a validation. And if I am to
add validation for every field I have to write as many showError()
functions as there are fields or write a huge switch statement inside
showError().

And if there are some checkboxes, radiobuttons and other select lists
then why should I write all this validation by hand? Maybe there is a way
to specify this validation in more simple way? Like saying that if $_POST
contains information about selection in some list then it should be
selected, and elesewhere it should validate automatically about selection
indices in list and so on.

Is it possible to do such things? Or maybe I should write my showError()
in Javascript instead? Or maybe I am wrong about the solution. What is
the "right way" of doing such things?
Hi,

You can also implement an array with critical fields id.
For each critical field, you do your check. In your array, in fact an
associative one with couples key =value, you put key = id and value
= {true or false} according your validation criteria.

Then, when this array is completely filled, for eack id with a false
value, you write "yellow/red/whatever signs".

$critical_items

Sep 24 '07 #2

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

Similar topics

2
by: yoelgold | last post by:
Hi I want to start writing a new site. It will include 3 forms that will collect information from the user. I know how to keep the info in sessions etc. my question is about the design of the...
6
by: ALthePal | last post by:
Hi, I'm not sure if we are able to or even how to loop through the web forms in a VB.NET project during design time. In MSAccess we are able to go through the database -> forms collection and...
14
by: Matt | last post by:
I want to know if ASP.NET Web Forms Validation Controls are Server-Side or Client-Side form validation? Since I think each validator control can select either 1) JavaScript based error dialog or 2)...
4
by: | last post by:
Hi Has anyone any experience using client side validation with asp.net forms. Specifically I'd like to know... 1. How do you attach client side code web controls (a button), like a...
8
by: TJS | last post by:
what are folks doing to get around limitation of one server form per page ?
5
by: excelleinc.com | last post by:
Hello, I have 2 forms to be filled by user, one is "auth" and second one contact form. They're completely independent. Problem is that when I enclose them within same <form runat="server"> tag...
3
by: nzanella | last post by:
Hello, I just ran into the restriction of ASP.NET allowing no more than one <form> tag with the runat="server" attribute per page. This seems like a big restriction to me. I ran across the...
3
by: Saket Mundra | last post by:
I have multiple web forms in my application. The user after logging on is directed to form1 where he enters information desired. Once finished he is directed to form2 and the same procedure goes on...
5
by: matt | last post by:
hello, i am on an interesting project. in this project, i have to create dynamic data-entry forms for offline-users to fill out, save locally, and eventually postback to our app (when back...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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,...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.