• Hello,
    I am new to coding plugins. So, please pardon me for asking this.

    I am trying to code a plugin where I need a checkbox along with two other text inputs.

    The values in text fields are being saved in database, but the checkbox value isn’t.

    Here is my code:

    function plugin_admin_init(){
    register_setting( 'my_settings', 'txt1' );
    register_setting( 'my_settings', 'txt2' );
    register_setting( 'my_settings', 'check1');
    }</p>
    <p>function plugin_options_page() {<br />
    ?></p>
    <p><div class="wrap"><br />
    <h2>My Plugin Settings</h2></p>
    <p><div class="postbox"><br />
    <h3 class="hndle" style="padding:5px 0 5px 10px;"><span>Video Size (Width & Height)</span></h3></p>
    <p><form method="post" action="options.php"><br />
        <?php settings_fields( 'my_settings' ); ?><br />
        <?php do_settings_sections( 'my_settings' ); ?><br />
        <table class="form-table"><br />
            <tr valign="top"><br />
            <th scope="row">Text Field 1</th><br />
            <td><input type="text" name="txt1" value="<?php echo get_option('txt1'); ?>" /></td><br />
            </tr></p>
    <p>        <tr valign="top"><br />
            <th scope="row">Text Field 2</th><br />
            <td><input type="text" name="txt2" value="<?php echo get_option('txt2'); ?>" /></td><br />
            </tr></p>
    <p>    <tr valign="top"><br />
            <th scope="row"></th><br />
        <td><input type="checkbox" name="check1" value="false"<?php if (get_option('check1')==true) echo 'checked="checked" '; ?>>My Checkbox</td><br />
    	</tr>        </p>
    <p>    <tr valign="top"><br />
            <th scope="row"></th><br />
        <td><input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /></td><br />
    	</tr><br />
    </table><br />
    </form><br />
    </div><br />

    Now, the check1 is being saved as false (option_value)in database, nothing else even if the checkbox is checked.

    My questions are,
    How can I save that (true or false) checkbox value, and
    How can I use a if statement is that value is true?

    Thanks

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘How to Save checkbox values in database for a plugin?’ is closed to new replies.