Jump to content

Problem Validating <select>


Darkness1427

Recommended Posts

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");
}

Link to comment
Share on other sites

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");

}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.