{"id":710,"date":"2023-09-08T08:00:00","date_gmt":"2023-09-08T06:00:00","guid":{"rendered":"https:\/\/www.fuhselab.de\/?p=710"},"modified":"2023-08-23T11:22:56","modified_gmt":"2023-08-23T09:22:56","slug":"html-formulare","status":"publish","type":"post","link":"https:\/\/www.fuhselab.de\/index.php\/2023\/09\/08\/html-formulare\/","title":{"rendered":"HTML Workshop 5"},"content":{"rendered":"\n<p>Die Webseite soll nun mit einem Formular versch\u00f6nert werden. Dieser Artikel stellt die Formularelemente vor\u2026<\/p>\n\n\n\n<!--more-->\n\n\n\n<p><strong>Formulare f\u00fcr die Webseite:<\/strong><\/p>\n\n\n\n<p>Mit dem form-Element werden im HTML Quelltext Formulare erstellt. Da HTML Formulare f\u00fcr Benutzereingaben so dringend gebraucht werden, macht es Sinn sich den Aufbau solcher Formulare genauer anzusehen.<\/p>\n\n\n\n<p>Der Grundaufbau sieht so aus:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;form action=\u201cDatei oder Pfad\u201c method=\u201cpost\u201c>\n\nVorname: &#91;Einzeiliges Eingabefeld]\n\n&lt;br \/>\n\n&lt;input type=\u201ctext\u201c name=\u201cvorname\u201c size=\u201c30\u2033 maxlength=\u201c30\u2033>\n\n&lt;input type=\u201csubmit\u201c value=\u201cAbsenden\u201c>\n\n&lt;input type=\u201creset\u201c value=\u201cReset\u201c>\n\n&lt;br \/>&lt;br \/>\n\n&lt;\/form><\/code><\/pre>\n\n\n\n<p>Noch grunds\u00e4tzlicher schaut die Sache so aus:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;form>\n\nFormular-Elemente und Beschriftung\n\n&lt;\/form><\/code><\/pre>\n\n\n\n<p>Das form-Element wird also ge\u00f6ffnet und bekommt noch einige Zusatzangaben mit auf den Weg (die hier teilweise noch fehlen). Innerhalb des form-Elementes werden dann die Beschriftungen und die einzelnen Formular-Elemente eingebaut.<\/p>\n\n\n\n<p>Wenn alle Formular-Elemente verbaut sind wird das form-Element wieder geschlossen.<\/p>\n\n\n\n<p>Der Grundaufbau ist also identisch zu allen anderen HTML-Elementen. Die Kunst der Formulargestaltung ist die optimale Anordnung der Formularelemente und von denen gibt es ganz sch\u00f6n viele\u2026<\/p>\n\n\n\n<p><strong>Eingabefelder und Textarea:<\/strong><\/p>\n\n\n\n<p>Das einfachste Formularelement ist das Eingabefeld. Es gibt zwei Varianten davon. Einmal ein leeres Eingabefeld und eines mit Textvorbelegung.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;form action=\u201cDateipfad\u201c method=\u201cpost\u201c accept-charset=\u201cutf-8\u2033>\n\nVorname: &#91;Einzeiliges Eingabefeld]\n\n&lt;br \/>\n\n&lt;input type=\u201ctext\u201c name=\u201cvorname1\u2033 size=\u201c30\u2033 maxlength=\u201c30\u2033>\n\n&lt;br \/>&lt;br \/>\n\nVorname: &#91;Einzeiliges Eingabefeld mit Textvorbelegung]\n\n&lt;br \/>\n\n&lt;input type=\u201ctext\u201c name=\u201cvorname2\u2033 size=\u201c30\u2033 maxlength=\u201c30\u2033 value=\u201cWert\u201c>\n\n&lt;\/form><\/code><\/pre>\n\n\n\n<p>Dann gibt es noch ein Eingabefeld f\u00fcr Passw\u00f6rter.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;form action=\u201cDateipfad\u201c method=\u201cpost\u201c accept-charset=\u201cutf-8\u2033>\n\nPasswort: &#91;Eingabefeld f\u00fcr Passw\u00f6rter]\n\n&lt;br \/>\n\n&lt;input type=\u201cpassword\u201c name=\u201cpasswort\u201c size=\u201c12\u2033 maxlength=\u201c12\u2033>\n\n&lt;\/form><\/code><\/pre>\n\n\n\n<p>Auch bei der Textarea, den Textfeldern gibt es verschiedene Varianten.<\/p>\n\n\n\n<p>Der Aufbau bleibt aber wie erw\u00e4hnt:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;form>\n\n&lt;textarea name=\u201cuser_eingabe\u201c cols=\u201c50\u2033 rows=\u201c10\u2033>&lt;\/textarea>\n\n&lt;textarea name=\u201cuser_eingabe\u201c cols=\u201c50\u2033 rows=\u201c10\u2033>Textvorbelegung&lt;\/textarea>\n\n&lt;textarea name=\u201cuser_eingabe\u201c cols=\u201c50\u2033 rows=\u201c10\u2033 readonly>Textausgabe&lt;\/textarea>\n\n&lt;\/form><\/code><\/pre>\n\n\n\n<p><strong>Auswahllisten und Dropdowns:<\/strong><\/p>\n\n\n\n<p>Ohne viel Worte \u2013 hier der HTML Quelltext zu den Auswahllisten:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;form action=\u201cDateipfad\u201c method=\u201cpost\u201c accept-charset=\u201cZeichencodierung\u201c>\n\nAuswahlliste: &#91;Dropdown]\n\n&lt;br \/>\n\n&lt;select name=\u201ctop5\u2033 size=\u201c1\u2033>\n\n&lt;option>Person 1&lt;\/option>\n\n&lt;option>Person 2&lt;\/option>\n\n&lt;option>Person 3&lt;\/option>\n\n&lt;option>Person 4&lt;\/option>\n\n&lt;option>Person 5&lt;\/option>\n\n&lt;\/select>\n\n&lt;br \/>&lt;br \/>\n\nAuswahlliste mit Mehrfachauswahl:\n\n&lt;br \/>\n\n&lt;select name=\u201cchart2\u2033 size=\u201c5\u2033 multiple=\u201cmultiple\u201c>\n\n&lt;option>Mensch 1&lt;\/option>\n\n&lt;option>Mensch 2&lt;\/option>\n\n&lt;option>Mensch 3&lt;\/option>\n\n&lt;option>Mensch 4&lt;\/option>\n\n&lt;option>Mensch 5&lt;\/option>\n\n&lt;\/select>\n\n&lt;br \/>&lt;br \/>\n\nAuswahlliste mit Mehrfachauswahl und Vorselektion:\n\n&lt;br \/>\n\n&lt;select name=\u201cchart2\u2033 size=\u201c5\u2033 multiple=\u201cmultiple\u201c>\n\n&lt;option>Lebewesen 1&lt;\/option>\n\n&lt;option selected=\u201cselected\u201c>Lebewesen 2&lt;\/option>\n\n&lt;option>Lebewesen 3&lt;\/option>\n\n&lt;option>Lebewesen 4&lt;\/option>\n\n&lt;option>Lebewesen 5&lt;\/option>\n\n&lt;\/select>\n\n&lt;br \/>&lt;br \/>\n\nAuswahlliste mit Absendewert:\n\n&lt;br \/>\n\n&lt;select name=\u201cchart2\u2033 size=\u201c5\u2033 multiple=\u201cmultiple\u201c>\n\n&lt;option>Kreatur 1&lt;\/option>\n\n&lt;option value=\u201cAbsendewert\u201c>Kreatur 2&lt;\/option>\n\n&lt;option>Kreatur 3&lt;\/option>\n\n&lt;option>Kreatur 4&lt;\/option>\n\n&lt;option>Kreatur 5&lt;\/option>\n\n&lt;\/select>\n\n&lt;br \/>&lt;br \/>\n\nVerschachtelte Auswahlliste:\n\n&lt;br \/>\n\n&lt;select name=\u201cNamen\u201c size=\u201c6\u2033>\n\n&lt;optgroup label=\u201cNamen mit A\u201c>\n\n&lt;option label=\u201cAnna\u201c>Anna&lt;\/option>\n\n&lt;option label=\u201cAchim\u201c>Achim&lt;\/option>\n\n&lt;option label=\u201cAndreas\u201c>Andreas&lt;\/option>\n\n&lt;\/optgroup>\n\n&lt;optgroup label=\u201cNamen mit B\u201c>\n\n&lt;option label=\u201cBerta\u201c>Berta&lt;\/option>\n\n&lt;option label=\u201cBarbara\u201c>Barbara&lt;\/option>\n\n&lt;option label=\u201cBernd\u201c>Bernd&lt;\/option>\n\n&lt;\/optgroup>\n\n&lt;optgroup label=\u201cNamen mit C\u201c>\n\n&lt;option label=\u201cCaesar\u201c>Caesar&lt;\/option>\n\n&lt;option label=\u201cChristine\u201c>Christine&lt;\/option>\n\n&lt;option label=\u201cChristian\u201c>Christian&lt;\/option>\n\n&lt;\/optgroup>\n\n&lt;\/select>\n\n&lt;br \/>&lt;br \/>\n\n&lt;\/form><\/code><\/pre>\n\n\n\n<p><strong>Radiokn\u00f6pfe:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;form action=\u201cDateipfad\u201c method=\u201cpost\u201c accept-charset=\u201cZeichencodierung\u201c>\n\nRadio-Buttons:\n\n&lt;br \/>\n\n&lt;input type=\u201cradio\u201c name=\u201cZahlmethode\u201c value=\u201cMastercard\u201c> Mastercard&lt;br>\n\n&lt;input type=\u201cradio\u201c name=\u201cZahlmethode\u201c value=\u201cVisa\u201c> Visa&lt;br>\n\n&lt;input type=\u201cradio\u201c name=\u201cZahlmethode\u201c value=\u201cAmericanExpress\u201c> American Express\n\n&lt;\/form><\/code><\/pre>\n\n\n\n<p><strong>Checkbox:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;form action=\u201cDateipfad\u201c method=\u201cpost\u201c accept-charset=\u201cZeichencodierung\u201c>\n\nCheckboxen:\n\n&lt;br \/>\n\n&lt;input type=\u201ccheckbox\u201c name=\u201czutat\u201c value=\u201csalami\u201c> Salami&lt;br>\n\n&lt;input type=\u201ccheckbox\u201c name=\u201czutat\u201c value=\u201cpilze\u201c> Pilze&lt;br>\n\n&lt;input type=\u201ccheckbox\u201c name=\u201czutat\u201c value=\u201csardellen\u201c> Sardellen\n\n&lt;\/form><\/code><\/pre>\n\n\n\n<p><strong>Upload-Formularfeld:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;form action=\u201cDateipfad\u201c method=\u201cpost\u201c accept-charset=\u201cZeichencodierung\u201c>\n\nUpload-Formularelement: &#91;hier ohne enctype=\u201cmultipart\/form-data\u201c im \u201eform-Element\u201c]\n\n&lt;br \/>\n\n&lt;input type=\u201cfile\u201c name=\u201cDatei\u201c size=\u201c50\u2033 maxlength=\u201c100000\u2033 accept=\u201ctext\/txt\u201c>\n\n&lt;br \/>&lt;br \/>\n\nVersteckte Formularfelder: &#91;Der Inhalt von \u201evalue\u201c wird versteckt \u00fcbermittelt]\n\n&lt;br \/>\n\n&lt;input type=\u201chidden\u201c name=\u201chiddeninfo\u201c value=\u201cDieses Formular wurde von Webseite X verschickt. Der Inhalt von value wird\n\nversteckt \u00fcbermittelt.\u201c>\n\n&lt;\/form><\/code><\/pre>\n\n\n\n<p><strong>Absende-Button und Reset Button:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;form action=\u201cDateipfad\u201c method=\u201cpost\u201c accept-charset=\u201cZeichencodierung\u201c>\n\n&lt;input type=\u201csubmit\u201c value=\u201cAbsenden \u201e>\n\n&lt;input type=\u201creset\u201c value=\u201cAbbrechen\u201c>\n\n&lt;\/form><\/code><\/pre>\n\n\n\n<p><strong>Fieldset und Legend:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;form action=\u201cDateipfad\u201c method=\u201cpost\u201c accept-charset=\u201cZeichencodierung\u201c>\n\nFormularelemente gruppieren:\n\n&lt;br \/>\n\n&lt;fieldset>\n\n&lt;legend>Absender&lt;\/legend>\n\n&lt;br \/>\n\n&lt;input type=\u201ctext\u201c size=\u201c40\u2033 maxlength=\u201c40\u2033 name=\u201cVorname\u201c>\n\n&lt;br \/>\n\n&lt;input type=\u201ctext\u201c size=\u201c40\u2033 maxlength=\u201c40\u2033 name=\u201cVorname\u201c>\n\n&lt;br \/>\n\n&lt;input type=\u201ctext\u201c size=\u201c40\u2033 maxlength=\u201c40\u2033 name=\u201cVorname\u201c>\n\n&lt;br \/>&lt;br \/>\n\n&lt;\/fieldset>\n\n&lt;\/form><\/code><\/pre>\n\n\n\n<p><strong>Klick-Buttons:<\/strong><\/p>\n\n\n\n<p>Buttons, also Schaltkn\u00f6pfe\/Schaltfl\u00e4chen k\u00f6nnen auch selber definiert werden\u2026<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;form action=\u201cDateipfad\u201c method=\u201cpost\u201c accept-charset=\u201cZeichencodierung\u201c>\n\n&lt;br \/>\n\nSchaltfl\u00e4che: &#91;Klick-Button ohne Event-Handler onclick]\n\n&lt;br \/>\n\n&lt;input type=\u201cbutton\u201c name=\u201cText 1\u2033 value=\u201cLED 01 einschalten\u201c>\n\n&lt;input type=\u201cbutton\u201c name=\u201cText 1\u2033 value=\u201cLED 01 ausschalten\u201c>\n\n&lt;br \/>&lt;br \/>\n\nSchaltfl\u00e4che mit Grafik: &#91;Klick-Button ohne Event-Handler onclick]\n\n&lt;br \/>\n\n&lt;input type=\u201cbutton\u201c name=\u201cText 1\u2033 value=\u201cLED 01 einschalten\u201c>\n\n&lt;input type=\u201cbutton\u201c name=\u201cText 1\u2033 value=\u201cLED 01 ausschalten\u201c>\n\n&lt;input type=\u201cimage\u201c src=\u201cDATEINAME\u201c alt=\u201cBild als Button\u201c>\n\n&lt;\/form><\/code><\/pre>\n\n\n\n<p><strong>Das kleine Beispiel-Formular:<\/strong><\/p>\n\n\n\n<p>Nochmal als Info: Diese Quelltexte sind noch keine vollst\u00e4ndigen Formulare sondern stellen nur die einzelnen Formularelemente vor.<\/p>\n\n\n\n<p>Ein kleines Beispiel-Formular k\u00f6nnte so aussehen:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;form action=\u201cDateipfad\u201c method=\u201cpost\u201c accept-charset=\u201cZeichencodierung\u201c>\n\nVorname:\n\n&lt;br \/>\n\n&lt;input type=\u201ctext\u201c name=\u201cvorname\u201c size=\u201c30\u2033 maxlength=\u201c30\u2033 value=\u201cVorname eintragen\u2026\u201c>\n\n&lt;br \/>&lt;br \/>\n\nNachname:\n\n&lt;br \/>\n\n&lt;input type=\u201ctext\u201c name=\u201cnachname\u201c size=\u201c30\u2033 maxlength=\u201c30\u2033 value=\u201cNachname eintragen\u2026\u201c>\n\n&lt;br \/>&lt;br \/>\n\n&lt;input type=\u201csubmit\u201c value=\u201cAbsenden \u201e>\n\n&lt;input type=\u201creset\u201c value=\u201cAbbrechen\u201c>\n\n&lt;\/form><\/code><\/pre>\n\n\n\n<p><strong>Textvorbelegung mit Placeholder:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;form action=\u201cDateipfad\u201c method=\u201cpost\u201c accept-charset=\u201cZeichencodierung\u201c>\n\n&lt;input type=\u201ctext\u201c name=\u201cvorname\u201c placeholder=\u201cMax Mustermann\u201c > Textvorbelegung\n\n&lt;\/form><\/code><\/pre>\n\n\n\n<p><strong>Pflichtfeld mit Required:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;form action=\u201cDateipfad\u201c method=\u201cpost\u201c accept-charset=\u201cZeichencodierung\u201c>\n\n&lt;input type=\u201ctext\u201c name=\u201cname\u201c required > Pflichtfeld mit required\n\n&lt;br \/>&lt;br \/>\n\n&lt;input type=\u201csubmit\u201c value=\u201cAbsenden \u201e>\n\n&lt;input type=\u201creset\u201c value=\u201cAbbrechen\u201c>\n\n&lt;\/form><\/code><\/pre>\n\n\n\n<p>Das neue \u201erequired\u201c Attribut ist schon der Knaller, wenn versucht wird das Formular leer abzuschicken, dann gibt es eine Warnung<\/p>\n\n\n\n<p><strong>Autofocus:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;form action=\u201cDateipfad\u201c method=\u201cpost\u201c accept-charset=\u201cZeichencodierung\u201c>\n\n&lt;input type=\u201ctext\u201c name=\u201cvorname\u201c required autofocus > Vorname Pflichtfeld mit required und autofocus\n\n&lt;input type=\u201ctext\u201c name=\u201cnachname\u201c required > Nachname Pflichtfeld mit required\n\n&lt;input type=\u201ctext\u201c name=\u201cort\u201c required > Ort Pflichtfeld mit required\n\n&lt;br \/>&lt;br \/>\n\n&lt;input type=\u201csubmit\u201c value=\u201cAbsenden \u201e>\n\n&lt;input type=\u201creset\u201c value=\u201cAbbrechen\u201c>\n\n&lt;\/form><\/code><\/pre>\n\n\n\n<p>Per \u201eautofocus\u201c wird der Cursor im entsprechenden Formularfeld positioniert.<\/p>\n\n\n\n<p><strong>Formularfeld f\u00fcr E-Mail:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;form action=\u201cDateipfad\u201c method=\u201cpost\u201c accept-charset=\u201cZeichencodierung\u201c>\n\n&lt;input type=\u201cemail\u201c name=\u201cvorname\u201c size=\u201c40\u2033 maxlength=\u201c40\u2033 placeholder=\u201cE-Mail Adresse eintragen\u201c > E-Mail Formularelement\n\n&lt;br \/>&lt;br \/>\n\n&lt;input type=\u201csubmit\u201c value=\u201cAbsenden \u201e>\n\n&lt;input type=\u201creset\u201c value=\u201cAbbrechen\u201c>\n\n&lt;\/form><\/code><\/pre>\n\n\n\n<p>F\u00fcr E-Mail Adressen gibt es ab HTML5 auch ein eigenes input-Element.<\/p>\n\n\n\n<p>Dieses neue Formularelement wird in PHP noch eine Rolle spielen, denn hier wird schon auf HTML Ebene ein Formularcheck durchgef\u00fchrt, ob eine g\u00fcltige Mailadresse eingegeben wurde.<\/p>\n\n\n\n<p><strong>Formularfeld f\u00fcr Webadresse:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;form action=\u201cDateipfad\u201c method=\u201cpost\u201c accept-charset=\u201cZeichencodierung\u201c>\n\n&lt;input type=\u201curl\u201c name=\u201cvorname\u201c size=\u201c40\u2033 maxlength=\u201c40\u2033 placeholder=\u201cWebadresse eintragen\u201c > Webadresse Formularelement\n\n&lt;br \/>&lt;br \/>\n\n&lt;input type=\u201csubmit\u201c value=\u201cAbsenden \u201e>\n\n&lt;input type=\u201creset\u201c value=\u201cAbbrechen\u201c>\n\n&lt;\/form><\/code><\/pre>\n\n\n\n<p>Auch das Webadresse-Feld pr\u00fcft schon die Eingabe<\/p>\n\n\n\n<p><strong>Formularfeld f\u00fcr Telefonnummer:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;form action=\u201cDateipfad\u201c method=\u201cpost\u201c accept-charset=\u201cZeichencodierung\u201c>\n\n&lt;input type=\u201ctel\u201c name=\u201cvorname\u201c size=\u201c40\u2033 maxlength=\u201c40\u2033 placeholder=\u201cTelefonnr. eintragen\u201c > Telefonnummer Formularelement\n\n&lt;br \/>&lt;br \/>\n\n&lt;input type=\u201csubmit\u201c value=\u201cAbsenden \u201e>\n\n&lt;input type=\u201creset\u201c value=\u201cAbbrechen\u201c>\n\n&lt;\/form><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Die Webseite soll nun mit einem Formular versch\u00f6nert werden. Dieser Artikel stellt die Formularelemente vor\u2026<\/p>\n","protected":false},"author":1,"featured_media":545,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[23],"class_list":["post-710","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-webdesign","tag-webdesign-gruppe-peine"],"_links":{"self":[{"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/posts\/710","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/comments?post=710"}],"version-history":[{"count":2,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/posts\/710\/revisions"}],"predecessor-version":[{"id":730,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/posts\/710\/revisions\/730"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/media\/545"}],"wp:attachment":[{"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/media?parent=710"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/categories?post=710"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/tags?post=710"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}