chadrt Posted May 21, 2007 Share Posted May 21, 2007 Hello, I am very new to PHP, a week to be exact, so bear with me. Last week I decided to build this database and create these interface pages and I may have made it more complicated than it should be but, well you know. I will describe the problem and give you a little background as well so that you will have everything you need. This is my very first attempt at PHP or MySQL stuff and I believe that this particular question has more to do with PHP than MySQL so here goes. I have a form http://ki4mve.com/cs this form has 3 sections which are just three individuale forms on one page. The third form has 5 fields that POST to a custom script that I created to show the contents of the database now I want the STATE field to always be filled in and I accomplished that but the other 4 fields I would like to have at least 3 characters in one of the remaining 4 fields! This will hopefully prevent too many entries from being displayed simultaneously and too many database entries from flooding the screen. How I am doing the STATE field: (Those are two single quotes not a double) if ($state==''){ echo "You must select a state to search in!"; } If I have been to vague please let me know what if anything you need and I will gladly post it. Thank you in advance to anyone who has a moment to spare in this request. ~Chad Link to comment https://forums.phpfreaks.com/topic/52384-solved-form-to-require-at-least-one-field-to-have-x-number-of-characters/ Share on other sites More sharing options...
per1os Posted May 21, 2007 Share Posted May 21, 2007 www.php.net/strlen I think that is what you are after...if not please post more code and describe the problem better. Link to comment https://forums.phpfreaks.com/topic/52384-solved-form-to-require-at-least-one-field-to-have-x-number-of-characters/#findComment-258498 Share on other sites More sharing options...
chadrt Posted May 21, 2007 Author Share Posted May 21, 2007 The results page broad-search.php has a $_POST for each field in my form and a hidden field in the form specifies which set of instrcutions will followed by the broad-search.php page. When the name and address section of the page is being used it has 5 fields that it listens to: Name Address City State zip What I want to happen: => When that form is used the field ZIP is a requirement, I have that accomplished. => Then the NAME, ADDRESS, or CITY not all of them or but just one of them, has to have at least 3 characters in it for it to do what it is supposed to do. Link to comment https://forums.phpfreaks.com/topic/52384-solved-form-to-require-at-least-one-field-to-have-x-number-of-characters/#findComment-258505 Share on other sites More sharing options...
per1os Posted May 21, 2007 Share Posted May 21, 2007 <?php $hasThree = false; if ((isset($_POST['NAME']) && strlen($_POST['NAME']) > 2) || (isset($_POST['ADDRESS']) && strlen($_POST['ADDRESS']) > 2) || (isset($_POST['CITY']) && strlen($_POST['CITY']) > 2)) { $hasThree = true; } if (!$hasThree) { die('Address, Name, Or City is required.'); // probably not DIE here but yea. } ?> Link to comment https://forums.phpfreaks.com/topic/52384-solved-form-to-require-at-least-one-field-to-have-x-number-of-characters/#findComment-258509 Share on other sites More sharing options...
chadrt Posted May 21, 2007 Author Share Posted May 21, 2007 Thank you that was the ticket right there I didnt know || were like "OR" from what I can see that is what it is and it worked great! Link to comment https://forums.phpfreaks.com/topic/52384-solved-form-to-require-at-least-one-field-to-have-x-number-of-characters/#findComment-258524 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.