Forums Forums Search Search Results for 'sf_input_object_pre'

Viewing 10 results - 61 through 70 (of 137 total)
  • Author
    Search Results

  • Anonymous
    Inactive

    OK so this is as far as I got:

    function filter_input_object($input_object, $sfid)
    {
    
    	if(($input_object['name']!='_sf_post_type')||($input_object['type']!='radio'))
    	{
    		return $input_object;
    	}
    	
    	foreach($input_object['options'] as $option)
    	{
    		if($option->value=="")
    		{
    			
    		}
    		else if($option->value=="post")
    		{
    			
    		}
    	}
    	
    	return $input_object;
    }
    add_filter('sf_input_object_pre', 'filter_input_object', 10, 2);

    All I need now is to assign actions for the ‘if’ and ‘elseif’. But I couldn’t find any example. I would like to hide or delete the option with no value and make the one with value ‘post’ preselected.

    Can you help please?

    #215959

    Ross
    Keymaster

    Hi Mark

    This would be the CSS, although how it works may vary from browser to browser:

    .searchandfilter .sf-field-category select option:first-child{
    	display: none;
    }

    This assumes that it is the field/class .sf-field-category that needs this applying to… You can inpsect the form (using your browsers dev tools) to find the class names of other fields you might want to do this to.

    However, I would recommend the PHP way using our filter to ensure consistency across browsers etc (add to functions.php):

    
    function filter_input_object($input_object, $sfid){
    	
    	if(($input_object['name']!='_sft_category'))
    	{
    		return $input_object;
    	}
    	
    	//if we want to filter the options generated, we need to make sure the options variable actually exists before proceeding (its only available to certain field types)
    	if(!isset($input_object['options']))
    	{
    		return $input_object;
    	}
    	
    	//now we know there are options we can go ahead anre remove the firlst option
    	array_shift($input_object['options']);
    	
    	
    	return $input_object;
    }
    add_filter('sf_input_object_pre', 'filter_input_object', 10, 2);
    

    In this example, I have used the same field (category), but using the URL fieldname – _sft_category.

    Thanks

    #215170

    Ross
    Keymaster

    Hi Andrew

    Your link went offline so I couldn’t see. I’m guessing you tried something like the following section of code (this adds a prefix / postfix outside the select field itself).

    Also, notice the name doesn’t have the brackets _sfm_distance:

    function filter_input_object($input_object, $sfid){
    	
    	if(($input_object['name']!='_sfm_distance')){
    		return $input_object;
    	}
    	
    	//add/override prefix & postfix to the field
    	$input_object['prefix'] = "Prefix ";
    	$input_object['postfix'] = " Postfix";
    	
    	return $input_object;
    }
    add_filter('sf_input_object_pre', 'filter_input_object', 10, 2);

    However if you wanted to change the labels (or in this case append text to it) it would be like:

    function filter_input_object($input_object, $sfid){
    	
    	if(($input_object['name']!='_sfm_distance')){
    		return $input_object;
    	}
    	
    	//if we want to filter the options generated, we need to make sure the options variable actually exists before proceeding (its only available to certain field types)
    	if(!isset($input_object['options'])){
    		return $input_object;
    	}
    	
    	//now we know there are options we can loop through each one, and change what we need
    	foreach($input_object['options'] as $option){
    		$option->label .= " miles";
    	}
    	
    	return $input_object;
    }
    add_filter('sf_input_object_pre', 'filter_input_object', 10, 2);

    Thanks

    PS – I’ve actaully tested both of these just now with my own field, so there shouldn’t be syntax errors.

    #215141

    Trevor
    Participant

    I had a thought. Try this:

    function add_miles_to_filter_labels($input_object, $sfid) {
      if(($input_object['name']!='_sfm_distance[]'||($sfid != 2216)) {
        return $input_object;
      }
      foreach($input_object['options'] as $option) {
        $option->label .= " miles";
      }
      return $input_object;
    }
    add_filter('sf_input_object_pre', 'add_miles_to_filter_labels', 10, 2);
    #214935

    Trevor
    Participant

    Spotted another errod, sorry.

    function add_miles_to_filter_labels($input_object, 2116) {
      if($input_object['name']!='_sfm_distance[]') {
        return $input_object;
      }
      foreach($input_object['options'] as $option) {
        $option->label .= " miles";
      }
      return $input_object;
    }
    add_filter('sf_input_object_pre', 'add_miles_to_filter_labels', 10, 2);
    #214927

    Trevor
    Participant

    It shouldn’t have the dollar symbol, no.

    I can see an error also, so try this:

    function add_miles_to_filter_labels($input_object, 2116) {
      if(($input_object['name']!='_sfm_distance[]') {
        return $input_object;
      }
      foreach($input_object['options'] as $option) {
        $option->label .= " miles";
      }
      return $input_object;
    }
    add_filter('sf_input_object_pre', 'add_miles_to_filter_labels', 10, 2);
    #214925

    Anonymous
    Inactive

    ok this is what I have so far:

    function add_miles_to_filter_labels($input_object, $2116) {
      if(($input_object['name']!='_sfm_distance[]') {
        return $input_object;
      }
      foreach($input_object['options'] as $option) }
        $option->label .= " miles";
      }
      return $input_object;
    }
    add_filter('sf_input_object_pre', 'add_miles_to_filter_labels', 10, 2);

    I’ve tried with and without the $ sign in front of the id, but I still get a parse error on the site.

    #214907

    Trevor
    Participant

    I would imagine the PHP would be something like:

    function add_miles_to_filter_labels($input_object, $sfid) {
      if(($input_object['name']!='_sfm_colours') {
        return $input_object;
      }
      foreach($input_object['options'] as $option) }
        $option->label .= " miles";
      }
      return $input_object;
    }
    add_filter('sf_input_object_pre', 'add_miles_to_filter_labels', 10, 2);

    where you change $sfid to the actual ID of the form AND
    where you change the string/name _sfm_colours to whatever the data_sf_field_name actually is, for example, see here:

    https://www.screencast.com/t/wlh2lKrVDj4

    #214759

    Anonymous
    Inactive

    Hello to update this I have now got the the code working correctly. Here shows 2 text replacement one after the other.

    function my_plugin_search_filter_change_label($input_object, $sfid) {
     if ($sfid == 845 && $input_object['name'] == '_sft_category') {
          
      foreach ($input_object['options'] as $key => $option) {
          if ($option->label == 'All Categories') {
    
            $input_object['options'][$key]->label = 'Toutes Catégories';
          }
        }
      foreach ($input_object['options'] as $key => $option) {
          if ($option->label == 'Accessories and Cables') {
    
            $input_object['options'][$key]->label = 'Accessoires et Câbles';
          }
        }
      }
     return $input_object;
    }
    
    add_filter('sf_input_object_pre', 'my_plugin_search_filter_change_label', 10, 2);
    #214482

    Anonymous
    Inactive

    I have tried it in the functions.php but I cant seem to get it to change word ‘Brochures’ to ‘Test’

    This is the code I have used am I missing something?

    <?php
    function my_plugin_search_filter_change_label($input_object, $sfid) {
      if ($sfid == 845 && $input_object['name'] == '_sft_file_type[]') {
        foreach ($input_object['options'] as $key => $option) {
          if ($option->label == 'Brochures') {
            $input_object['options'][$key]->label = 'Test';
          }
        }
      }
      return $input_object;
    }
    add_filter('sf_input_object_pre', 'my_plugin_search_filter_change_label', 10, 2);
    ?>
Viewing 10 results - 61 through 70 (of 137 total)