We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16732
    • 592 Posts
    Hi, I have created a custom module and I’m facing a insolvable (form me) problem:

    I have serveral checkboxs named (delimg1, delimg2, etc..) and in the result part of my script I’m using $_POST["delimg$i"] to check if the variables was sent and in the case I’m using the value.

    I’m using something la this :
                        for ($i=1;$i<=$_POST['totalImg'];$i++){
                                    if (isset($_POST["delimg$i"]) ){
                                       ....
                                    }
    
                        }
    


    The module is working, BUT when I select less all the chekboxs I have a MODx "Undefined index:delimgNOTSELECTED" alert and I really dont know how to correct my module script.

    I initialize all my variables but here I don’t know how to do it because I don’t know how many checkboxs I will have.

    It’s the only thing I have to do before my client can use the all site, so I really need help ! Thanks A LOT



      • 11975
      • 2,542 Posts
      Hi laurent,

      I’ve faced the same issue with tvEditor smiley

      To fix it I’ve used strpos to find the prefix name of the variable in the posted value.
      hope that helps

      :-)

      here is the function
      
      <?php
      
      	function handleValue($external,$allowed=array()){
      	
      	$posted= array();
      	
      	if(!is_array($external)) return false;
      	
      		foreach($external as $key => $value){
      			
      			if(in_array($key,$allowed) || (strpos($key,implode("," ,$allowed))!==false)){
      				
      				if(is_array($value) && (strpos($key,"option") !== FALSE) ){
      				
      					$posted['options'] = $this->handleOptionsValues($posted['options'],$key,$value);
      				
      				}else{
      				
      					$posted[$key] =  $value ;
      					
      				}
      			
      			}elseif(is_array($string = explode("_",$key)) && in_array($string[0],$allowed)){
      			
      				$posted[$string[0]][] = $value ;
      			}
      		}
      	
      	return $posted;
      	
      	}
      


      $tveditor->posted = $tveditor->functions->handleValue($_REQUEST,$tveditor->allowed);
        Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
        • 16732
        • 592 Posts
        Thanks for your help !...
        I will try all this but I think you once again save my live ! laugh
          • 16732
          • 592 Posts
          I made a shorter version of your function... it’s WORKSSSSSSS .... MERCIIIIII !!
            • 11975
            • 2,542 Posts
            You’re welcome Laurent grin

            :-)
              Made with MODx : [url=http://www.copadel.com]copadel, fruits et l