0

Instead of reloading i need to submit the data by ajax. it is because theme options having customized tab sections and all the fields are in array in a single field of settings api.

//Displaying and saving options data
function amna_theme_options_page () {
settings_errors('theme_amna'); 
?>
<div class="wrap flex-tab">
    <form action='options.php' method='post' class="amna-fields">
        <?php 
        settings_fields( 'amna-fields-group' );
        amna_do_settings_sections('theme_amna'); ?>
        <p class="submit"><input type="submit" class="button-primary" value="<?php _e( 'Save changes', 'amna_save_settings' ); ?>" /></p>
    </form>
</div>
<?php 
}

Here is my function to wrapping the fields in html not table

function amna_do_settings_sections($page) {
global $wp_settings_sections, $wp_settings_fields;

if ( !isset($wp_settings_sections) || !isset($wp_settings_sections[$page]) )
    return;

foreach( (array) $wp_settings_sections[$page] as $section ) {
    echo "<h3>{$section['title']}</h3>\n";
    call_user_func($section['callback'], $section);
    if ( !isset($wp_settings_fields) ||
         !isset($wp_settings_fields[$page]) ||
         !isset($wp_settings_fields[$page][$section['id']]) )
            continue;
    echo '<div class="settings-form-wrapper">';
    amna_do_settings_fields($page, $section['id']);
    echo '</div>';
 }
 }

function amna_do_settings_fields($page, $section) {
global $wp_settings_fields;

if ( ! isset( $wp_settings_fields[ $page ][ $section ] ) ) {
    return;
}

foreach ( (array) $wp_settings_fields[$page][$section] as $field ) { ?>
    <div class="settings-form-row flex-tab">
        // Here is my tab defined by not posting right now
        <?php if ( !empty($field['args']['label_for']) )
            echo '<p><label for="' . $field['args']['label_for'] . '">' .
                $field['title'] . '</label><br />';
        else
        call_user_func($field['callback'], $field['args']);
        echo '</p>';
    echo '</div>';
}

}

So instead of reloading i want to submit the fields value by ajax.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.