plugins – Passing an input variable through a switch statement

Question

I am having trouble with getting the $repLevel variable to pass between two php files in this plugin; the initial php file where the form itself will submit a selected option and send it to a processor page (2nd block of code), but how to get the result from the switch statement back to the initial plugin file to print/display the result is where I’m struggling.

This is the front-facing form that would appear on the site

function ifWrap($content) {
            //check if we're on the page selected in the settings
            if ( is_page(get_option('lp_actPage')) ) {
                $container="";
                $container .= '<form method="post" action="'.plugin_dir_url(__FILE__).'inc/">';
                $container .= '<label for="rep-type">I want to contact my</label>';
                $container .= '<select name="repLevel" id="level">';
                $container .= '<option value="">Select a level</option>';
                $container .= '<option value="first">Local and county</option>';
                $container .= '<option value="second">State</option>';
                $container .= '<option value="third">National</option>';
                $container .= '</select>';
                $container .= '<input type="submit" name="repType" value="Find"/>';
                $container .= '</form>';
                return $content . $container;
            }
         
            return $content;
        }
add_filter('the_content', array($this, 'ifWrap',9,2));

This is the processing code containing the switch statement

<?php
    $path = preg_replace('/wp-content.*$/','',__DIR__);
    require_once($path. "wp-load.php");
    
    if(isset($_POST['repType'])){
            
        $repLevel = sanitize_text_field($_POST['repType']);
            
        switch ($repLevel){
            case 'first':
                echo "code for first choice";
                break;
            case 'second':
                echo "code for second choice";
                break;
            case 'third':
                echo "code for third choice";
                break;
            default:
            echo "please choose among the options in the dropdown";                 
        }
        return $repLevel;
    }
?>

Apologies if this is redundant, but I’m looking to return that $repLevel variable such that the result from the switch statement shows up below the select form on the front-side of the site.
T-i-a for any insights

0
710dev_null 1 day 2022-09-23T08:08:53-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse