plugins – Passing an input variable through a switch statement


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 .= '<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

    $path = preg_replace('/wp-content.*$/','',__DIR__);
    require_once($path. "wp-load.php");
        $repLevel = sanitize_text_field($_POST['repType']);
        switch ($repLevel){
            case 'first':
                echo "code for first choice";
            case 'second':
                echo "code for second choice";
            case 'third':
                echo "code for third choice";
            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

710dev_null 5 months 2022-09-23T08:08:53-05:00 0 Answers 0 views 0

Leave an answer