Darkness1427 Posted June 8, 2011 Share Posted June 8, 2011 heyy i have a page with a fair sized form and two dropdown boxes (select options), for the php validation i am quite simply using if($_POST['boxOne'] == 0){ $errors[] = ""; } the boxes dont have labels so the first <option> is the title/label with a value of 0 so this should catch that, works fine for one but not for the other. any ideas. the files ascoiated with the problems are failry hefty ones so if you want to view the entire code just ask, else this is the code in question. <tr> <td height="30"></td> <td height="30"> <input type="text" name="minPPW" class="propertyHalfInput" placeholder="Min PPW" value="<?php echo $form->value("minPPW") ?>"/> * [b]<select name="available" class="propertyDropDownHalf" id="available"> <option value="0">Available For</option> <option value="11/12">2011/12</option> <option value="12/13">2012/13</option> <option value="13/14">2013/14</option> <option value="14/15">2014/15</option> </select>[/b] * </td> <td width="10" height="30"></td> <td height="30" colspan="4"> <span>TV Subscribtion:</span> <input type="hidden" name="billTV" id="billTV" value="0"/> </td> <td width="5" height="30"></td> <td width="25" height="30"> <input name="billTV" type="checkbox" id="billTV" value="1" /> </td> </tr> <tr> <td height="30"></td> <td height="30"> <input type="text" name="maxPPW" class="propertyHalfInput" placeholder="Max PPW" value="<?php echo $form->value("maxPPW") ?>"/> * [b]<select name="propType" class="propertyDropDownHalf" id="propType"> <option value="0">Property Type</option> <option value="House">House</option> <option value="Flat">Flat</option> <option value="Halls">Halls</option> </select>[/b] * </td> <td width="10" height="30"></td> <td height="30" colspan="4"> <span>Internet Subscription:</span> <input type="hidden" name="billNet" id="billNet" value="0"/> </td> <td width="5" height="30"></td> <td width="25" height="30"> <input name="billNet" type="checkbox" id="billNet" value="1" /> </td> </tr> and if($_POST['propType'] == 0){ $form->setError("type", "* The property Type is required"); } if($_POST['available'] == 0){ $form->setError("available", "* Availability is required"); } Quote Link to comment https://forums.phpfreaks.com/topic/238777-problem-validating/ Share on other sites More sharing options...
Pikachu2000 Posted June 8, 2011 Share Posted June 8, 2011 You should create an array of the valid values for each <select> and validate against that. Since there is a limited number of options available, those should be the only ones accepted as valid values. Otherwise, it would be easy for a malicious user to submit any value they wanted, including attempting SQL injection attacks via those fields. $avail_vals = array( '11/12', '12/13', ' 13/14', '14/15 ); if( !in_array($_POST['available'], $avail_array) ) { $form->setError("type", "* The property Type is required"); } Quote Link to comment https://forums.phpfreaks.com/topic/238777-problem-validating/#findComment-1226938 Share on other sites More sharing options...
Darkness1427 Posted June 8, 2011 Author Share Posted June 8, 2011 thanks for pointin that out, i have incorporated this into my code but i still get the same error even thoigh i choose an option in the available drop down it returns an error saying i haven't. i have followed the script all the way through and it is identical to the property type script except for it having the availibility options etc. Quote Link to comment https://forums.phpfreaks.com/topic/238777-problem-validating/#findComment-1226999 Share on other sites More sharing options...
Pikachu2000 Posted June 8, 2011 Share Posted June 8, 2011 Post the current code that's causing problems. Quote Link to comment https://forums.phpfreaks.com/topic/238777-problem-validating/#findComment-1227014 Share on other sites More sharing options...
Darkness1427 Posted June 8, 2011 Author Share Posted June 8, 2011 i fixed it thanks, it was the / for some reason it didnt like them so i just replaced them with -, crude but it works, thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/238777-problem-validating/#findComment-1227026 Share on other sites More sharing options...
Darkness1427 Posted June 8, 2011 Author Share Posted June 8, 2011 heyy you know how to work mkdir() code = <?php echo dirname( __FILE__ ); if(!file_exists("/nate")){ var_dump(mkdir("/nate", 0777)); } ?> it not printing anything to screen which suggests that /nate exists but cannot find the physical folder anywhere in my site directory Quote Link to comment https://forums.phpfreaks.com/topic/238777-problem-validating/#findComment-1227042 Share on other sites More sharing options...
Pikachu2000 Posted June 8, 2011 Share Posted June 8, 2011 By having the leading slashes, you're telling the script to look for and create a directory in the filesystem's root. If you want it created in the current directory, drop the slashes. Since you're working with directories, take a look at is_dir as well. Quote Link to comment https://forums.phpfreaks.com/topic/238777-problem-validating/#findComment-1227108 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.