Zapis z formularza do bazy
-
Witam, otóż mam taki pewnie błahy problem a jednak.. 🙂
Chodzi o to że formularz wtyczki nie zapisuje danych z formularza w bazie. Tabele ładnie tworzy ale nie przekazuje :plik function.php
// rejestrujemy style w panelu admina function admin_plugin_theme() { wp_enqueue_style('admin-plugin-theme', plugins_url('../css/bolter.css', __FILE__)); } add_action('admin_enqueue_scripts', 'admin_plugin_theme'); add_action('login_enqueue_scripts', 'admin_plugin_theme'); // menu wtyczki function bolter_menu() { add_menu_page( 'Bolter', 'Filtr', 'administrator', 'filtr', 'bolter_page' ); // add_submenu_page( 'filtr', 'Bolter', 'Panel','administrator', 'panel', 'bolter_page' ); add_submenu_page( 'filtr', 'Bolter', 'Ustawienia','administrator', 'ustawienia', 'bolter_options' ); } add_action( 'admin_menu', 'bolter_menu'); // strona filtra function bolter_page() { if ( !current_user_can( 'manage_options' ) ) { wp_die(__( 'oj.. chyba oszukujemy co ?' ) ); } include 'bolter-template.php'; } //strona ustawien wtyki function bolter_options () { if ( !current_user_can('manage_options')) { wp_die(__('Oj.. chyba oszukujemy co ?')); } include 'bolter-setting.php'; } // tworzymy tabelę function rmlc_install() { global $wpdb; $prefix = $wpdb->prefix; $rmlc_tablename = $prefix . "bolter"; $rmlc_db_version = "1.0"; if ($wpdb->get_var("SHOW TABLES LIKE '" . $rmlc_tablename . "'") != $rmlc_tablename) { $query = "CREATE TABLE " . $rmlc_tablename . " ( id int(20) NOT NULL AUTO_INCREMENT, kee text NOT NULL, admin_message text NOT NULL, mail text NOT NULL, confirm int(10) NOT NULL, PRIMARY KEY (id) )"; $wpdb->query($query); add_option("rmlc_db_version", $rmlc_db_version); } } // kasowanie tabeli function rmlc_uninstall() { global $wpdb; $prefix = $wpdb->prefix; $rmlc_tablename = $prefix . "bolter"; $query ='DROP TABLE '.$rmlc_tablename; $wpdb->query($query); } // zapisuję ustawienie pobrane z formularza function save_setting() { rmlc_install(); if (isset($kee) && isset($adminMessage) && isset($mail)) { $kee = $POST['kee']; $adminMessage = $POST['admin_message']; $mail = $POST['mail']; if ($kee && $adminMessage && $mail) { $ins = \mysql_query("INSERT INTO wp_bolter kee='$kee', admin_message='$adminMessage', mail='$mail' "); if($ins) { echo "pomyslnie dodano rekord"; }else echo "nie dodano"; } } }
.. i plik bolter-setting.php
<h3 class="title">Ustawienia</h3> <form method="post" action="" id="send-form" enctype="multipart/form-data"> <p><label for="ping_sites">Należy zapisać slowa kluczowe, po przecinku na ktore filtr bedzie wylanial podejrzane wiadomosci a nastepnie, poinformuje wskazane osoby ze strony o zagrozeniu :</p> <textarea name="kee" id="ping_sites" class="large-text code" rows="3"></textarea> <p><label for="ping_sites">Wiadomość jaką dostanie administrator w przypadku uzycia slowa kluczowego z filtra przez uzytkownika : </p> <textarea name="admin_message" id="ping_sites" class="large-text code" rows="3"></textarea> <p><label for="ping_sites">Mail/ maile dla powiadomien :</p> <input name="mail" type="text" id="admin_email" class="regular-text ltr" /> <fieldset> <p><label for="users_can_register"> <input name="users_can_register" type="checkbox" id="users_can_register" value="1" checked='checked' /> Powiadomomić na maila ? </label></p> </fieldset> <p class="submit"> <input type="submit" name="submit" id="submit" class="button button-primary" value="Zapisz zmiany" /></p> </form> <?php save_setting()?>
W wordpress robi się to jakoś inaczej jak standardowo ? 🙂
- Temat ‘Zapis z formularza do bazy’ jest zamknięty na nowe odpowiedzi.