Last active
January 13, 2019 18:08
-
-
Save radarin/052e902bb102706678772f829e60f78e to your computer and use it in GitHub Desktop.
Formular zum hinzufügen neuer Daten
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Adminbereich, neuer Eintrag */ | |
add_shortcode('rad-glossar-admin-insert', 'radGlossarAdminInsert'); | |
function radGlossarAdminInsert() { | |
// Das Formular wird nur dem Admin angezeigt | |
if(current_user_can('administrator')){ | |
// Hier die URL eintragen, auf welcher die Seite verwendet wird | |
$url = "https://computer-for-dummies.ch/glossar/eintrag"; | |
$ausgabe = "<p class='glossartitel'>Neuer Eintrag</p>"; | |
if(!isset($_POST['glossar_term']) OR $_POST['glossar_term'] == "" ){ | |
$ausgabe .= "<form action='".$url."' METHOD='post'>"; | |
$ausgabe .= "<p class='glossarfieldname' class='glossartitel'>Begriff</p>"; | |
$ausgabe .= "<p><input type='text' name='glossar_term' value='' maxlength='50' class='glossarfield'></p>"; | |
$ausgabe .= "<p class='glossarfieldname'>Beschreibung</p>"; | |
$ausgabe .= "<p><textarea name='glossar_description' wrap='virtual' class='glossararea'></textarea></p>"; | |
$ausgabe .= "<p><input type='Submit' value='Speichern' class='glossarbutton' </p>"; | |
$ausgabe .= "</form>"; | |
} | |
// Speichert das Formular, wenn der Inhalt von 'term' nicht leer ist. | |
if(isset($_POST['glossar_term']) AND $_POST['glossar_term'] != ""){ | |
// Daten eintragen | |
global $wpdb; | |
$wpdb->insert( | |
$wpdb->prefix.'rad_glossar', | |
array( | |
'glossar_term' => $_POST['glossar_term'], | |
'glossar_description' => $_POST['glossar_description'] | |
), | |
array( | |
'%s', // term | |
'%s' // description | |
// %s steht für String (Text), %d für Integer (ganze Zahlen) und %f für Float (Gleitkommazahlen). | |
) | |
); | |
$id = $wpdb->insert_id; | |
if($id != false){ | |
$ausgabe .= "<p class='glossarinfo-true'>Der neue Begriff wurde eingetragen</p>"; | |
} else { | |
$ausgabe .= "<p class='glossarinfo-false'>Beim Eintragen ist ein Fehler aufgetreten</p>"; | |
} | |
} | |
} else { $ausgabe .= "<p class='glossarinfo-false'>Sie haben keine Berechtigung für diese Funktion.</p>"; } | |
return $ausgabe; | |
} // --- END Funktion | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment