Welcome Guest, Not a member yet? Register   Sign In
Validation sum of input
#1

(This post was last modified: 06-03-2017, 08:30 AM by kenji.)

hello

i want to validate sum of input array equal 100

if i post form with this value : 
blanc : 30
brun : 50
cuisine : 60
informatique : 70
telephonie : 80
autre : 90
if sum not equal 100, i send an error, i must have 100


html : 

Code:
<div class="tab-cell w50prc">
    <label class="spe"><span>*</span> Répartition activité :</label>
    <p class="inline-block w50prc"><input type="text" placeholder="% Blanc" name="repartition[blanc]" id="repartition[blanc]" value="(-$infos.blanc-)"></p>
    <p class="inline-block w50prc"><input type="text" placeholder="% Brun" name="repartition[brun]" id="repartition[brun]" value="(-$infos.brun-)"></p>
    <p class="inline-block w50prc"><input type="text" placeholder="% Cuisine" name="repartition[cuisine]" id="repartition[cuisine]" value="(-$infos.cuisine-)"></p>
    <p class="inline-block w50prc"><input type="text" placeholder="% Informatique" name="repartition[informatique]" id="repartition[informatique]" value="(-$infos.informatique-)"></p>
    <p class="inline-block w50prc"><input type="text" placeholder="% Téléphonie" name="repartition[telephonie]" id="repartition[telephonie]" value="(-$infos.telephonie-)"></p>
    <p class="inline-block w50prc"><input type="text" placeholder="% Autre" name="repartition[autre]" id="repartition[autre]" value="(-$infos.autre-)"></p>
</div>


PHP Code:
$this->ci->form_validation->set_rules('repartition[]''répartitions''trim|callback_checkTotalRepartitionsTest[repartition]'); 

This works but the test is performed 6 times, which is not good

PHP Code:
   public function checkTotalRepartitionsTest($str,$field){
 
       if(array_sum($_POST[$field])<>100){
 
           return FALSE;
 
       }
 
   

thanks
Reply


Messages In This Thread
Validation sum of input - by kenji - 06-03-2017, 08:20 AM
RE: Validation sum of input - by Avenirer - 06-04-2017, 07:50 AM
RE: Validation sum of input - by kenji - 06-04-2017, 07:58 AM
RE: Validation sum of input - by Wouter60 - 06-04-2017, 01:01 PM
RE: Validation sum of input - by lloricode - 06-04-2017, 08:34 PM
RE: Validation sum of input - by PaulD - 06-05-2017, 11:32 AM



Theme © iAndrew 2016 - Forum software by © MyBB