Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7607579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:41:59+00:00 2026-05-31T00:41:59+00:00

I’m developing a WordPress plugin. There are multiple form elements, and for some reason,

  • 0

I’m developing a WordPress plugin. There are multiple form elements, and for some reason, each time I click the submit button on one form, it tells another form to submit. This is inconvenient, because when I click the button to save new information, the other form deletes the first row from the database.

Javascript:

//This is the Javascript that controls the remove all form.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<script type="text/javascript">
    $(document).ready(function(){
        $('tr.assoc_row').show();
        $('#settings-removed-msg').hide();
        $('#formdeleteassoc').submit(function(e){
            e.preventDefault(); //Works to prevent normal submission of the form.

            $.ajax ({
                type: 'POST',
                url: '',
                data: {remove_all: ''
                },
                success: function() {
                    $('#settings-removed-msg').fadeIn('fast'); //Working now
                    $('tr.assoc_row').fadeOut('fast'); //Working now
                    }
            });

        });
    });
</script>

HTML

<!-- This the the HTML and PHP that renders the options page in WordPress. -->
<div class="wrap">
    <?php screen_icon('plugins'); ?>
    <h2>Tag to Category Associator</h2>
    <div id="settings-removed-msg" class="updated"><p>Associations were successfully removed.</p></div>
    <form action="<?php echo $_SERVER['PHP_SELF'].'?page=tag2cat-associator'; ?>" method="post">


    <?php
    settings_fields('cb_t2c_options');
    do_settings_sections('tag2cat-associator');
    ?>

    <input name="Submit" type="submit" value="Save Changes" />
    </form></div>

PHP

//These are the form elements.

//Show the buttons to remove all associations and remove a single association.
    echo '<table>';
    echo '<tr>';
        echo '<td></strong>Remove existing associations</strong></td>';
        echo "<td><form action='" . $_SERVER['PHP_SELF'] . "?page=tag2cat-associator' method='post'>";
        echo "<select name='remove_single' id='removeSingle' class='remove-single' >";
            foreach ($cb_t2c_show_associations as $tags) {
            echo "<option value = '".$tags->assoc_ID."'>".$tags->assoc_ID."</option>";
            }
        echo '</select>';
        echo "&nbsp;<input type = 'submit' name='submit-remove' value='Remove'></input>";
    echo '</form></td></tr>';
    echo '<tr>';
        echo '<td>Remove all (Will delete existing associations)</td>';
        echo "<td><form action='" . $_SERVER['PHP_SELF'] . "?page=tag2cat-associator' id='formdeleteassoc' method='post'>";
        echo "<input name='remove_all' id='removeAll' class='remove-all' type='submit'  value='Remove All'></input></form></td></tr>";
    echo '</table>';

//The if's alter the database if the right $_POST information occurs.
if ( isset( $_REQUEST['remove_all'] ) ){
        $wpdb->query("DELETE FROM ".$prefix."cb_tags2cats");
        }

    if ( isset( $_REQUEST['remove_single'] ) ) {
        $remove_assoc = $_REQUEST['remove_single'];
        $wpdb->query("DELETE FROM ".$prefix."cb_tags2cats WHERE assoc_ID = " . $remove_assoc);
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:42:00+00:00Added an answer on May 31, 2026 at 12:42 am

    The problem was due to having 2 settings_fields as registered settings in WordPress. The basic structure was:

    function cb_t2c_admin_init() {
    register_setting('cb_t2c_options', 'cb_t2c_options' /*'cv_t2c_validate_options'*/);
    
        //Define sections and settings
        add_settings_section(
            //This defined the settings section.
            );
    
        add_settings_field(
            //This defined the first setting, with a call to a function.
            );
    
        add_settings_field(
            //This defined the unwanted setting.
        );
    
    }
    

    What I wanted to accomplish with WordPress was to have a section outside the form, which would show the user the currently selected options in a simple HTML table. Therefore, I deleted the second ‘add_settings_field’ function, took the contents of its callback function and put it at the end of the function that draws the options page. E.g.,

    //Draw the options page
    function cb_t2c_plugin_options_page () {
        $cb_t2c_remove_all_url = plugin_dir_url( _FILE_ ) . 'remove_all.php';
    ?>
    
        <div class="wrap">
        <?php screen_icon('plugins'); ?>
        <h2>Title</h2>
        <div id="new-assoc-msg" class="updated"><p>Data was successfully added.</p></div>
        <form id="formsavesettings" name="save_settings" action="<?php echo $_SERVER['PHP_SELF'].'?page=the_options_page'; ?>" method="post">
    
        <?php
        settings_fields('cb_t2c_options');
        do_settings_sections('section_name');
        ?>
    
        <input name="Submit" type="submit" value="Save Changes" />
        </form></div>
        <?php
    
    // Here is where I added the PHP code to show my table full of already selected values.
    // This is accomplished with 1 settings section and 1 settings field.
    // By previously putting the code in a settings field, I was telling WordPress to pass along the values to the form.
    };
    

    This does not yet take care of the SQL injection vulnerability, but it does explain why an unintended value was getting passed to the form.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have some data like this: 1 2 3 4 5 9 2 6
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.