Adding a button without submitting the form using the options api
-
I’ve registered my fields with
add_settings_field('excluded_users', 'Users to exclude', 'teamsheet_arg_callback', 'teamsheet_plugin','teamsheet_plugin_section',array('excluded_users'));
In my callback I have:
<input id="excluded_users" name="teamsheet_plugin_options[excluded_users]" type="hidden" value="<?php echo $value;?>" /> <input type='text' id='userBox' /><button onclick="javascript: addUser();">Add/Remove</button> <script> function addUser(){ } </script>
I was expecting the “Add/Remove” button to run the AddUser() function which in turn would append (or remove) the user from the list contained in the “excluded_users” hidden input value.
Instead, the Options are submitted, a message comes up which says “Settings saved” and the options are committed to the database.
Is there any way to allow the onclick event to be processed without saving the options? The form has a submit button:
<input name="Submit" type="submit" value="<?php esc_attr_e('Save Changes'); ?>" />
How do I make sure that the form is only submitted on clicking this?
- The topic ‘Adding a button without submitting the form using the options api’ is closed to new replies.