• I am wondering what is the best way to handle data validation when using settings_fields(‘myoption-group’).

    Right now on my options page I have created two options, a temp_option and a regular option that updates on page load. This way when the data is passed to options.php it is validated on the next load.

    This kinda seems like a backwards way of doing it however, and I was wondering if anyone knew of any built in functions for handling data validation while using settings_fields(‘myoption-group’) and options.php

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

    (@spike117)

    anything?

    spike, came across your question, looking for the same answer…

    the whitelist_options routine does some basic deep_slashes but i was looking for a way to strip my saved data from html tags.

    the only thing i could come up with was a simple routine to filter the saved options afterwards. let me explain with an example.

    after the options get updated, options.php sends the browser back to the referring page with ?updated=true appended to the URL. at the beginning of my options page routine i added a function like this:

    $option = get_option('my_plugin_option');
    
    if ( 'true' == $_GET['updated'] ) {
     if ($option == "") {
      delete_option('my_plugin_option');
      echo '<div id="message" class="updated fade"><p><strong>[remove message]</strong></p></div>';
      unset ($option); }
     elseif ($option != strip_tags($option,'')) {
       $option = strip_tags($option,'');
       update_option('custom_css',$custom_css);
       echo '<div id="warning" class="error fade"><p><strong>[warning message]</strong></p></div>';
     }
    }

    If there is anyone around who can tell me a more elegant way to do this, i would appreciate some pointers very much 🙂

    thanks!

    RavanH, i don’t know if you are still following he thread, but for your plugin, i can suggest the following: use the sanitize call back of the register_setting function when adding options to the whitelist.

    <?php register_setting( $option_group, $option_name, $sanitize_callback ); ?> few details here.

    thanks jmbamba, for that great pointer! looks like just the thing i am looking for… will investigate as soon as i get some time 🙂

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Data Validation and settings_fields( ‘myoption-group’ );’ is closed to new replies.