• I need some help with the structure of some dynamic content in my custom template, for my WP site.
    I want to show a drop down menu (FORM) and have the user select a value. Then show a different form that has results based on the query of a custom DB using the initial selection. This form allowing some selections and comments, before writing back to the DB.
    I have done this before in PHP but not in WordPress. My FORM works perfectly as does the reading and writing to the DB.
    My issue is that I can’t get the FORMs to display. I have tried to use a global variable to manage the display of each FORM. The primary will display, but upon selection it will not show the second FROM.

    My code below, note I have removed the bulk of the HTML and PHP code to make it easier to read:

    
        global $wpdb;
        $GLOBALS['Air'] = '';
        $Air = $GLOBALS['Air'];
    //<!------------------------Create FORMs--------------------------------------------------->
    //Always show the form
    echo '<form action="#v_form" method="post" id="v_form">';
    If ($Air == "")
        {
        //    Primary input
        //    Create HTML drop down list from custom DB. Select one item from list. (works)
        }
       
    If ($Air != "")
        {
        //    Secondary input, check box selection and comments field
        //    Query DB based on previous selection of "Air", show results and allow user input. (works)
        }
        ?>
        <tr><td></td><td><input type="submit" name="submit_form" value="submit" /></td></tr>
        </table></form>
    <?php
    //<!------------------------ Form action Primary and secondary write to DB--------------------------------------------------->
    if (isset($_POST['submit_form']))
        { 
        if ($_POST['air'] != "" && $Air == '' )
            {
            // Set Air variable and then show other input
            $Air = $_POST["air"];
            $GLOBALS['Air'] = $Air;
            }
        if ($_POST["2ndinput"] != "" && $Air != '' )
            {
    
            //add loop for each check box and write to DB
            foreach($_POST["2ndinput"] as $2ndinput) 
                {
                // Write to DB
                }//end foreach
            echo "<p>Written to the database. Thanks!!</p>";
            }
        } else 
            {
            //set variables to default and reset FORM
            //$Air = "";
            }
    ?>
    

    Should the Submit action be above or below the FORM in the script? How can I create a variable to manage the FORM action?

    Any assistance appreciated. tks

Viewing 1 replies (of 1 total)
  • If I were doing this I would have javascript react to the drop down menu selection. Have all the different forms in their own hidden div with unique ID, have the javascript display the right one and hide all the rest.

Viewing 1 replies (of 1 total)

The topic ‘Dynamic content template’ is closed to new replies.