Jump to content

Combining Example Code!


CraigMcKee

Recommended Posts

Hi, 

I'm so close to having this work how I want but one last thing! 

I have a form with a drop down box with the numbers 1 - 60 in.  I have created a view that returns any numbers people have submitted with their login names, e.g. 

1 - Laurie 

4 - Craig 

What I need to happen is it to list all the empty numbers too, so like this: 

1 - Laurie

2 - 

3 - 

4 - Craig 

5 - 

etc

This code removes numbers that have already been selected from the drop down box (so after Laurie and Craig had chosen 1 & 4 the drop down box would now show 2, 3, 5, 6 etc) 

https://pastebin.com/dAps0kqJ

and this code subtotals the rider numbers (I was just trying to get a custom view to work so am pleased this returns something) 

https://pastebin.com/A7MwSQ2S

Using the first code how do I edit the second code so that it displays every number whether a user has chosen it or not? 

Thank you!! 

 

Link to comment
Share on other sites

Ah ok, sorry.  Code that removes used items from drop down: 

add_filter('frm_setup_edit_fields_vars', 'frm_remove_selected', 20, 2);
add_filter('frm_setup_new_fields_vars', 'frm_remove_selected', 20, 2);
function frm_remove_selected($values, $field){
    if ( in_array( $field->id ==6, array(range(0,60)) ) ) {
        $used = FrmEntryMeta::get_entry_metas_for_field( $field->id );
        if ( $used ) {
            $used_vals = array();
            
            foreach ( $used as $u ) {
                if ( is_array( $u ) ) {
                    foreach ( $u as $item ) {
                        $used_vals[] = $item;
                        unset($item);
                    }
                } else {
                    $used_vals[] = $u;
                }
                unset($u);
            }
            if ( $field->type == 'data' ) {
                foreach ( $used_vals as $u ) {
                    if ( isset($values['options'][$u]) ) {
                        unset($values['options'][$u]);
                    }
                    unset($u);
                }
            } else {
                $values['options'] = array_diff( $values['options'], $used_vals );
            }
        }
    }
    return $values;
}

And code that returns a total of rider numbers (largely useless but at least I know I can get it to return something!)

add_filter('frm_after_display_content', 'add_view_total_to_after_content', 30, 4);
function add_view_total_to_after_content($after_content, $display, $show, $atts){
    if ( $display->ID == 145 ) {
        $entries = $atts['entry_ids'];
        $total = 0;
        foreach($entries as $entry){
            $current_value = FrmProEntriesController::get_field_value_shortcode(array( 'field_id' => 6, 'entry' => $entry ) );
            if ( $current_value ) {
                $total += $current_value;
            }
        }
        $after_content = str_replace('[sum_6]', $total, $after_content);
    }
    return $after_content;
}

What I need to do is get the second code to loop through all items in the drop down (field id 6) irrelevant of whether they have been selected and return drop down number (field id 6) and rider name (field id 7). 

Does that make sense? 

Link to comment
Share on other sites

I'm so close to this working!! 

I have this code: 

add_filter('frm_after_display_content', 'add_view_total_to_after_content', 30, 4);
function add_view_total_to_after_content($after_content, $display, $show, $atts){

    $entries = $atts['entry_ids'];

	for ($x = 1; $x <= 10; $x++) {
		
	foreach($entries as $entry){
        	
	if ($x == FrmProEntriesController::get_field_value_shortcode(array( 'field_id' => 6, 'entry' => $entry ))) {
    	echo "$x - Rider match ";
			echo (FrmProEntriesController::get_field_value_shortcode(array( 'field_id' => 7, 'entry' => $entry)));
		}	else {

	}
} 
		echo "$x - <br>";
	} 
}

But it displays repeated numbers after printing values in the form:

 

1 - Rider match Laurie1 - 
2 - 
3 - 
4 - 
5 - 
6 - Rider match Craig McKee6 - 
7 - 
8 - 
9 - 
10 - 

Where have I gone wrong in my loop? 

Link to comment
Share on other sites

I have it working but of course now have two further questions...

1 - how can I get the value from field id 9 and 2 - how can I return all this information now using shortcode rather than echo?

add_filter('frm_after_display_content', 'add_view_total_to_after_content', 30, 4);
function add_view_total_to_after_content($after_content, $display, $show, $atts){

    $entries = $atts['entry_ids'];
        
    for ($x = 1; $x <= 10; $x++) {
        $ridername = "";
        
    foreach($entries as $entry){
        
    if ($x == FrmProEntriesController::get_field_value_shortcode(array( 'field_id' => 6, 'entry' => $entry ))) {
           $ridernumber = $x;
        $ridername = (FrmProEntriesController::get_field_value_shortcode(array( 'field_id' => 7, 'entry' => $entry)));
        }
                            }
    
    if ($ridername == "") {echo "$x - br";}
    if ($ridername != "") {echo "$ridernumber - $ridername br";}
    
    }      
}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.