• Resolved cybershot

    (@cybershot)


    I have a simple plugin that I am trying to make. I made the plugin, made the form for the admin area with a checkbox. If the checkbox is checked, I want to display some content on the homepage. If it is not checked, then I want the content to go away. So on the homepage, I put this in


    if(get_option('yes') != 'true')
    {
    if(function_exists('add_google_subscribe_form'))
    add_google_subscribe_form();
    }

    My problem is that the code ignores the if statement and shows the content. Doesn’t matter if the checkbox is checked or not. Here is my plugin code. It is very short


    <?php
    add_action('admin_menu', 'adding_content_admin_menu');

    function adding_content_admin_menu() {
    add_options_page('Add Content Option', 'Feedburner Signup Form','manage_options','AddFeedburner','adding_content_to_homepage');
    }

    function adding_content_to_homepage() {
    ?>
    <p>Add Home Home Page SignUp Form?</p>

    <form id="myForm" action="" method="post">
    <table width="200" border="0">
    <tr>
    <td>Yes</td>
    <td><input type="checkbox" checked="checked" id="yes" value="true" name="yes"></td>
    </tr>
    <tr>
    <td>No</td>
    <td><input type="checkbox" id="no" id="no" value="false" name="no"></td>
    </tr>
    </table>
    <input type="submit" value="submit" name="submit">
    save
    </form>

    <?php

    }
    ?>

    <?php
    function add_google_subscribe_form() {
    $content = "<div id=\"wrapper\">
    <div id=\"background\">
    <div id=\"emailForm\">
    <p>Enter Your Email</p>
    <form action=\"https://feedburner.google.com/fb/a/mailverify\" method=\"post\" target=\"popupwindow\" onsubmit=\"window.open('https://feedburner.google.com/fb/a/mailverify?uri=MtScottChurchOfGod', 'popupwindow', 'scrollbars=yes,width=550,height=520');return true\">
    <input id=\"emailInput\" type=\"text\" name=\"email\" />
    <input type=\"hidden\" value=\"MtScottChurchOfGod\" name=\"uri\"/>
    <input type=\"hidden\" name=\"loc\" value=\"en_US\"/>
    <input id=\"button\" type=\"submit\" value=\"\" />
    </form>
    </div><!--END emailForm-->
    </div><!--END background-->
    </div>";

    echo($content);
    }
    ?>

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter cybershot

    (@cybershot)

    I am not sending the option to the database. It’s hard coded. I just need to figure out how to get the form to communicate with the get_option. The codex is zero help to me on this

    Thread Starter cybershot

    (@cybershot)

    I finally found a tutorial that was written well enough to help me figure it out.

    https://blancer.com/tutorials/50837/how-to-integrate-an-options-page-into-your-wordpress-theme/

    If you do not send to the database, then get_option won’t work because it reads from the db. As you were told you need to use update_option to save the “yes” to the db. If you do not save it then when they click off the page there is no “yes”. Or where do you expect it to be stored? Especially as you do not specify an action in the form.
    How about something like this for your form function:

    $google_subscribe = get_option('google_subscribe_form');
    <form method="post">
    <label for="google_subscribe_form">yes or no:
    <input type="text" name="google_subscribe_form" value="<?=$google_subscribe_form?>" />
      </label>
    <input type="submit" name="submit" value="Submit" />
    </form>

    Then you can use something like this:

    function WHATEVER
    if (get_option("google_subscribe_form") == no){
    if(function_exists('add_google_subscribe_form'))
    add_google_subscribe_form();
    }

    This is quick and kind of off the top of my head. But generally speaking is a better direction I think.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘help with plugin development’ is closed to new replies.