adv Posted September 18, 2007 Share Posted September 18, 2007 hello i wanna made a form that has the year but i don`t wanna make it with list i want them to put the year instead like : 07 ,, 08 how do i do it in php to give error if they put something else something like this $ar = array("07","08","09","10"); foreach ($ar as $year) etc etc i think something like that thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/69737-some-help/ Share on other sites More sharing options...
GingerRobot Posted September 18, 2007 Share Posted September 18, 2007 Well, if you did want to just check against a list of possible values, you could use the in_array() function. However, it would probably be easier to treat the input as a number, and just check it is within whatever parameters you want. Quote Link to comment https://forums.phpfreaks.com/topic/69737-some-help/#findComment-350394 Share on other sites More sharing options...
adv Posted September 18, 2007 Author Share Posted September 18, 2007 can u give me an example please i dont quite understand Quote Link to comment https://forums.phpfreaks.com/topic/69737-some-help/#findComment-350402 Share on other sites More sharing options...
AV1611 Posted September 18, 2007 Share Posted September 18, 2007 you want them to enter year into a box or select it from a pulldown? (pull down is better) If they type in the year, you have to verify it's a valid year OR verify that year exists in the database as written. Pulldown created dynamically (select distinct year from table order by year asc...) seems the best to me, not knowing what you are looking for... Quote Link to comment https://forums.phpfreaks.com/topic/69737-some-help/#findComment-350406 Share on other sites More sharing options...
adv Posted September 18, 2007 Author Share Posted September 18, 2007 AV yes i want them to type it down not box i know with box is there a function that can do this or something simillary please help have last 2 digits of year "07" "08" "09" and if they type something else it must give error Quote Link to comment https://forums.phpfreaks.com/topic/69737-some-help/#findComment-350417 Share on other sites More sharing options...
AV1611 Posted September 18, 2007 Share Posted September 18, 2007 AV yes i want them to type it down not box i know with box Sorry, I'm not able to understand what you just said do you A. want pulldown boxes B. want them to type the data into a text field Quote Link to comment https://forums.phpfreaks.com/topic/69737-some-help/#findComment-350421 Share on other sites More sharing options...
adv Posted September 18, 2007 Author Share Posted September 18, 2007 AV : B but when someone types something else then "07" "08" "09" I want to show an error message how do i check in the field box that?? hope you understand now :| Quote Link to comment https://forums.phpfreaks.com/topic/69737-some-help/#findComment-350423 Share on other sites More sharing options...
AV1611 Posted September 18, 2007 Share Posted September 18, 2007 Well, I would allow them to enter from 1 to 4 digits (regex to verify they are numbers only) then maybe pad left with 0's if the string length = 1 then set $variable=subst($whatever,-2,2) and that would always give you a number with leading 0 if they only put a "7" which lazy people like me do Quote Link to comment https://forums.phpfreaks.com/topic/69737-some-help/#findComment-350432 Share on other sites More sharing options...
AV1611 Posted September 18, 2007 Share Posted September 18, 2007 $variable=subst($whatever,-2,2) before I get corrected... $variable=subst($whatever,-2) would be adequate Quote Link to comment https://forums.phpfreaks.com/topic/69737-some-help/#findComment-350451 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.