I am making a plugin the place I’ve a dashboard that’s accomplished with Settings API
. I am attempting to save lots of knowledge from that kind through AJAX
.
Kind:
public operate agy_dashboard_page() {
?>
<kind id="agy-form-submit" motion="options.php" methodology="post">
<?php
settings_errors( 'agy_settings_fields' );
wp_nonce_field( 'agy_dashboard_save', 'agy_form_save_name' ); // CHECK THIS AT THE END
settings_fields( 'agy_settings_fields' );
?>
<div id="agy-tab1" class="agy-tabcontent">
<?php do_settings_sections( 'agy_settings_section_tab1' ); ?>
</div>
<?php
submit_button(
__( 'Save Adjustments', 'agy' ),
'',
'agy_save_changes_btn',
true,
array( 'id' => 'agy-save-changes-btn' )
);
if ( wp_doing_ajax() ) {
wp_die();
}
?>
</kind>
<?php
if ( ! isset( $_POST['agy_form_save_name'] ) ||
! wp_verify_nonce( $_POST['agy_form_save_name'], 'agy_dashboard_save' ) ) {
return;
}
?>
<?php
}
Register Settings:
public operate agy_register_settings() {
register_setting( 'agy_settings_fields', 'agy_settings_fields', 'agy_sanitize_callback' );
// Including sections
add_settings_section( 'agy_section_id', __( 'Basic', 'agy' ), array(
$this,
'agy_settings_section_callback'
), 'agy_settings_section_tab1' );
// Basic web page fields
add_settings_field( 'agy_section_id_enabled_disabled', __( 'Allow / Disable', 'agy' ), array(
$this,
'agy_section_id_enabled_disabled'
), 'agy_settings_section_tab1', 'agy_section_id' );
add_settings_field( 'agy_section_id_unregister_user', __( 'Present for unregistered customers solely', 'agy' ), array(
$this,
'agy_section_id_unregister_user'
), 'agy_settings_section_tab1', 'agy_section_id' );
add_settings_field( 'agy_section_id_debug_mode', __( 'Activate Debug mode', 'agy' ), array(
$this,
'agy_section_id_debug_mode'
), 'agy_settings_section_tab1', 'agy_section_id' );
}
AJAX:
operate agyAjaxSubmit() {
var agyFormData = new FormData(this);
agyFormData.append('agy_save_changes_btn', 1);
agyFormData.append('safety', agy_public_ajax.agy_publisher_name);
$.ajax({
sort: 'POST',
url: agy_admin_ajax.ajax_ajaxurl,
knowledge: agyFormData,
processData: false,
contentType: false,
success: operate () {
console.log('work');
},
error: operate () {
console.log('not work');
}
});
return false;
}
$('#agy-form-submit').submit(agyAjaxSubmit);
With out AJAX
, it is working high-quality. However with AJAX
, it is not saving any knowledge.
Any assistance is appreciated.