kenwvs Posted July 13, 2006 Share Posted July 13, 2006 HiThe form I am working on and trying to validate is for an online auction when you want to list multiple items at once. Basically all the fields needed to be completed are on the form, and then the form goes on to list the items.In a couple of the fields, I need a more complicated validation, and not sure if it is possible. It is basically like this...Validate a field called bid_increment:If the item_type is auction or dutch auction then bid_increment must be filled in with a dollar amountIf the item_type is fixed price or classified then bid_increment must be left empty.** The item_type is a drop down box and the bid_incrment is a text boxI am not sure if it is possible to write a function like this.I also have a drop down box for item_category. The default answer for this box is "Please select category" Can a function be written to allow anything except "Please Select Category", as they have then selected a valid category.Thanks,Ken Quote Link to comment https://forums.phpfreaks.com/topic/14469-a-function-for-form-validation-if-this-happens-do-that-resolved/ Share on other sites More sharing options...
GingerRobot Posted July 13, 2006 Share Posted July 13, 2006 Yes that is all possible:the first part:[code]<?php$bid_increment = $_POST['bid_increment'];$item_type = $_POST['item_type'];if($item_type == "auction" or $item_type=="dutch auction"){if(!(is_numeric($bid_increment) && is_int($bid_increment + 0)) OR empty($bid_increment)){ echo "Invalid bid increment"; exit; } else{ echo "Valid bid increment"; }}elseif($item_type == "fixed price" OR $item_type=="classified"){ if(!empty($bid_increment)){ echo "you can have no bid increment with this item type!";}}?>[/code]This assumes that you have given the options within the dropdown box the same value as i have e.g.:<option value="auction">Auction</option><option value="dutch auction">Dutch Auction</option>etc Quote Link to comment https://forums.phpfreaks.com/topic/14469-a-function-for-form-validation-if-this-happens-do-that-resolved/#findComment-57240 Share on other sites More sharing options...
GingerRobot Posted July 13, 2006 Share Posted July 13, 2006 And for the second, again it depends on how you name the options in the dropdown box[code]<?php$item_category = $_POST['item_category'];if($item_category == "0")//assumes you gave it the value 0{echo "no category selected";exit;}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14469-a-function-for-form-validation-if-this-happens-do-that-resolved/#findComment-57242 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.