SO网友:Adam J.
我把所有东西都打扫了一点。现在看起来是这样的:
ajax.js
function ajaxSubmit(e){
var nazwa_szkolenia = document.getElementById("nazwa_szkolenia").value;
var Data_szkolenia = document.getElementById("Data_szkolenia").value;
var Godzina = document.getElementById("Godzina").value;
var Max_pacjent = document.getElementById("Max_pacjent").value;
var dataString = [];
dataString[\'nazwa_szkolenia1\'] = nazwa_szkolenia;
dataString[\'Data_szkolenia1\'] = Data_szkolenia;
dataString[\'Godzina1\'] = Godzina;
dataString[\'Max_pacjent1\'] = Max_pacjent;
if (nazwa_szkolenia == \'\' || Data_szkolenia == \'\' || Godzina == \'\' || Max_pacjent == \'\') {
alert("Wypełnij wszystkie pola");
} else {
// prevent the default action.
e.preventDefault();
//var myform= jQuery(this).serialize();
jQuery.ajax({
type:"GET",
// Get the admin ajax url which we have passed through wp_localize_script().
url: ajax_object.ajax_url,
action: "submitAjaxForm",
data: dataString,
error: function(jqXHR, textStatus, errorThrown){
console.error("The following error occured: " + textStatus, errorThrown);
},
success:function(data){
console.log(dataString);
}
});
}
return false;
}
arcode-functions.php:
<?php
function registerFormAction(){
add_action(\'wp_ajax_nopriv_submitAjaxForm\',\'submitAjaxForm_callback\');
add_action(\'wp_ajax_submitAjaxForm\',\'submitAjaxForm_callback\');
}
function submitAjaxForm_callback(){
global $wpdb;
$nazwa_szkolenia2 = $_GET[\'nazwa_szkolenia1\'];
$Data_szkolenia2 = $_GET[\'Data_szkolenia1\'];
$Godzina_szkolenia2 = $_GET[\'Godzina1\'];
$Max_pacjent2 = $_GET[\'Max_pacjent1\'];
$result = $wpdb->insert( $wpdb->modul_terminarz, array(
\'Nazwa_szkolenia\' => $nazwa_szkolenia2,
\'Data_szkolenia\' => $Data_szkolenia2,
\'Godzina_szkolenia\' => $Godzina_szkolenia2,
\'Typ_szkolenia\' => \'1\',
\'Ile_miejsc_max\' => $Max_pacjent2,
\'Pelna_obsada\' => \'0\',
) );
wp_die();
}
add_action(\'init\', \'registerFormAction\');
?>
该代码保留在我的
menu.php:
// Hook for adding admin menus
add_action(\'admin_menu\', \'create_Terminarz_menu\');
// action function for above hook
/**
* Adds a new top-level page to the administration menu.
*/
function create_Terminarz_menu() {
add_menu_page(
\'ARCode Terminarz\',
\'Terminarz\',
\'manage_options\',
\'zarzadzanie-terminami\',
\'tm_zarzadzanie_terminami_odp\',
plugins_url(\'images/terminarz.png\', __FILE__),\'2.2.10\'
);
add_submenu_page( \'zarzadzanie-terminami\', \'ARCode Terminarz\' . \'Terminy szkoleń\', \'<b style="color:#E46500;">Terminy szkoleń</b>\', \'manage_options\', \'zarzadzanie-terminami\', \'tm_zarzadzanie_terminami_odp\');
add_submenu_page( \'zarzadzanie-terminami\', \'ARCode Terminarz\' . \'Pacjenci\', \'Pacjenci\', \'manage_options\', \'pacjenci\', \'tm_zarzadzanie_pacjentami_odp\');
add_action(\'admin_enqueue_scripts\',\'load_custom_wp_admin_js\');
}
/**
* Display callback for the Unsub page.
*/
function tm_zarzadzanie_pacjentami_odp() {
}
function load_custom_wp_admin_js($hook){
wp_register_script( \'jquery.min.js\', plugin_dir_url( __FILE__ ) . \'js/jquery.min.js\', array(\'jquery\'));
wp_enqueue_script( \'jquery.min.js\' );
wp_enqueue_style( \'kalendarz\',plugin_dir_url( __FILE__ ) . \'kalendarz.css\',false,\'1.1\',\'all\' );
wp_register_script( \'ajax-script\', plugin_dir_url( __FILE__ ) . \'ajax_js.js\');
wp_localize_script(\'ajax-script\', \'ajax_object\', array(\'ajax_url\' => admin_url(\'admin-ajax.php\')));
wp_enqueue_script( \'ajax-script\', plugin_dir_url( __FILE__ ) . \'ajax_js.js\');
}
/**
* Display callback for the Unsub page.
*/
function tm_zarzadzanie_terminami_odp() {
include_once( \'arcode-functions.php\');
include_once( \'kalendarz.php\');
?>
<div class="wrap" style="position: fixed;
width: 85%;
top: 40px;
bottom: 80px;">
</div>
<?php
}
在中
kalendarz.php 我拥有预订日历和表单的所有功能,这是我需要发送的表单:
this.createFormular = function () {
var ob = this.o;
var Admin_Form = document.createElement(\'form\')
Admin_Form.name=\'Formularz_Admin\';
Admin_Form.method=\'GET\';
Admin_Form.action=\'\';
var tabela = document.createElement(\'table\');
tabela.className = \'formular-table\';
var tr = document.createElement(\'tr\');
tabela.appendChild(tr);
var td = document.createElement(\'td\');
td.appendChild(document.createTextNode(\'Nazwa szkolenia: \'));
tr.appendChild(td);
tr.appendChild(td);
td.appendChild(Input_Name_Training);
var tr = document.createElement(\'tr\');
tabela.appendChild(tr);
var td = document.createElement(\'td\');
td.appendChild(document.createTextNode(\'Data szkolenia: \'));
tr.appendChild(td);
tr.appendChild(td);
td.appendChild(Input_Date_Training);
var tr = document.createElement(\'tr\');
tabela.appendChild(tr);
var td = document.createElement(\'td\');
td.appendChild(document.createTextNode(\'Godzina szkolenia: \'));
tr.appendChild(td);
tr.appendChild(td);
td.appendChild(Input_Hour_Training);
var tr = document.createElement(\'tr\');
tabela.appendChild(tr);
var td = document.createElement(\'td\');
td.appendChild(document.createTextNode(\'Max ilość osób: \'));
tr.appendChild(td);
tr.appendChild(td);
td.appendChild(Input_How_Many_People);
var tr = document.createElement(\'tr\');
tabela.appendChild(tr);
var td = document.createElement(\'td\');
td.appendChild(document.createTextNode(\' \'));
tr.appendChild(td);
tr.appendChild(td);
td.appendChild(Input_Form_Send);
Admin_Form.appendChild(tabela);
this.divForm.appendChild(Admin_Form);
};
我试着检查一下
submitAjaxForm
正在工作,正如scott所说,我已经与echo进行了检查,但没有给出任何结果。DataString提供正确的数组,但data提供0。。。我不知道我做错了什么;/我不知道注册submitAjaxForm的钩子是否不好,在我看来,所有钩子都可以。。。?