zavin Posted May 5, 2010 Share Posted May 5, 2010 I have a form listed below that you can currently select 1 of 3 values. I want to be able to use all 3 values at once. Once the submit button is hit the form need to ad the total of the 3 values to verify that it is greater than 0 and less than $value_ available. I also need the 3 values submitted separately so they can e inserted into their respective data bases. I sure I'm just over thinking the solution. Any help would be appreciated. <form method='post'> You can currently use <?php echo $value_available; ?> value. <input type='text' name='energy' value='0' size='5' maxlength='5'> <select name='type'> <option value='1'>Value 1</option> <option value='2'>Value 2</option> <option value='3'>Value 3</option> </select> <input type='submit' name='value' value='Use Value'> </form> Link to comment https://forums.phpfreaks.com/topic/200773-form-input-options/ Share on other sites More sharing options...
phpchamps Posted May 5, 2010 Share Posted May 5, 2010 Hello, Below is the solution.. .. That was a simple stuff i believe.. ... you should have tried this assignment...Hope u get good marks... <?php $value_available = 5; ?> <form method='post'> You can currently use <?php echo $value_available; ?> value. <input type='text' name='energy' value='0' size='5' maxlength='5'> <select name='type[]' multiple="true"> <option value='1'>Value 1</option> <option value='2'>Value 2</option> <option value='3'>Value 3</option> </select> <input type='submit' name='value' value='Use Value'> </form> <?PHP if(!empty($_POST)){ if(!empty($_POST['type'])){ $posted_val = $_POST['type']; $total = 0; foreach($posted_val as $key=>$val){ $total = $total + $val; } if($total > 0 && $total < $value_available){ echo "Success"; }else{ echo "Fail"; } // THREE SUBMITTED VALUES CAN BE FIND IN $_POST['type'] array } } Enjjoyyyyyyyyyy. Link to comment https://forums.phpfreaks.com/topic/200773-form-input-options/#findComment-1053554 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.