Forum Moderators: coopster

Message Too Old, No Replies

Field validation.on a different basis.

         

tonynoriega

7:13 pm on May 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How can i create a form that validates that at least 1 field has data?

for instance, right now i have that you have to at least search by "last name", but i want to be able to say that "you must enter data into at least one search criterion"

and have the form validate that at least one, doesnt matter which field...has data entered into the field...

current script:_____________________________________________
if (isset($_POST['submit'])) {

if (!$_POST['lname'])
{
echo'<table>
<tr>
<td><h3>You must enter a last name to query data</h3></td>
</tr>
</table>';
}

Frasnko

7:26 pm on May 14, 2007 (gmt 0)

10+ Year Member



i would like to help but I don't see what you are asking for? Does your script not work?
what does the form look like?
what kind of validation do you want to perform?

tonynoriega

7:48 pm on May 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The form has 2 fields. It is used to query a MySQL database for records and display them.

You can search by First Name or Last Name. Right now i have it so that you must at least query by Last Name. I am going to add 30 more fields for users to query records..

I want them to at least enter data into one field to query the database, but i dont care what field it is....just one.

if they dont, error...if they do, it displays the records...

i already have the rest of the script done, but i want to change this area of validation from validating one field of last name, to validating that at least one field has data...and again, it doesnt matter what field...

hope i clarified that...
thanks

Frasnko

7:52 pm on May 14, 2007 (gmt 0)

10+ Year Member



you may want to try looping through the post array and dealing with it through a case switch (http://www.php.net/switch), with the default case adding a value that will keep you from having an error.