{"id":3840,"date":"2011-07-11T20:46:37","date_gmt":"2011-07-11T18:46:37","guid":{"rendered":"http:\/\/notizblog.org\/?p=3840"},"modified":"2021-09-28T23:22:11","modified_gmt":"2021-09-28T21:22:11","slug":"html5-input-types-form-validierung-und-wordpress","status":"publish","type":"post","link":"https:\/\/notiz.blog\/2011\/07\/11\/html5-input-types-form-validierung-und-wordpress\/","title":{"rendered":"HTML5, Input-Types, Form-Validierung und WordPress"},"content":{"rendered":"\n<figure class=\"wp-block-image alignright\" style=\"max-width:50%\"><img decoding=\"async\" src=\"https:\/\/notiz.blog\/wp-content\/uploads\/2011\/07\/HTML5_Logo_256.png\" alt=\"HTML5 Logo\" \/><\/figure>\n\n\n\n<p>Dass HTML5 ein paar neue input-types definiert, habe ich durch die <a href=\"http:\/\/microformats.org\/wiki\/hcard-input-brainstorming#HTML5_input_types\">hcard-input-brainstorming<\/a> so am Rande auf geschnappt, mir aber nichts weiter dabei gedacht&#8230; Durch Zufall bin ich heute aber \u00fcber folgenden <a href=\"http:\/\/twitter.com\/sprungmarkers\/status\/90305500108947457\">Tweet<\/a> von Sylvia Egger gesto\u00dfen:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n    <p>Just implemented native <a rel=\"tag\" class=\"hashtag u-tag u-category\" href=\"https:\/\/notiz.blog\/tag\/html5\/\">#HTML5<\/a> form validation on #wp comments form &#8211; it&#x27; quite simple &amp; should be in #wp default theme<\/p>\n<\/blockquote>\n\n\n\n<p>und habe bissle recherchiert&#8230; Mit den neuen Input-Types ist es doch tats\u00e4chlich m\u00f6glich Input-Felder \u00fcber den Browser validieren zu lassen&#8230; Ich bin begeistert! \ud83d\ude42<\/p>\n\n\n\n<p>Tr\u00e4gt man beispielsweise eine Nicht-Email-Adresse in folgendes Feld&#8230;<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">input<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"email\"<\/span> \/&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code-Sprache:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>bekommt man&#8230;<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/notiz.blog\/wp-content\/uploads\/2011\/07\/firefox-email-validation.jpg\" alt=\"Email Validation im Firefox\" \/><\/figure>\n\n\n\n<p>Sch\u00f6n wenn man sich noch \u00fcber solche Kleinigkeiten freuen kann oder \ud83d\ude09<\/p>\n\n\n\n<p>Lange rede kurzer Sinn: Da WordPress alle Formulare an zentraler Stelle definiert, ist es ziemlich einfach sie mit ein paar neuen Input-Types zu versehen. Mit dem folgenden Code wird das Kommentar-Formular mit den Typen &quot;email&quot; und &quot;url&quot; und das Suchformular mit dem Typ &quot;search&quot; (funktioniert nur in den WebKit-Browsern) erweitert:<\/p>\n\n\n\n<p><ins><strong>Code-Update<\/strong>: <a href=\"https:\/\/yatil.de\/\">Eric Eggert<\/a> hat mich in den <a href=\"https:\/\/notiz.blog\/2011\/07\/11\/html5-input-types-form-validierung-und-wordpress\/#comment-173210\">Kommentaren<\/a> darauf hingewiesen, dass man mit <code>&lt;input required \/&gt;<\/code> auch noch die Pflichtfelder validieren kann. Danke!<\/ins><\/p>\n\n\n\n<p><ins><strong>Code-Update 2<\/strong>: Dank <a href=\"https:\/\/www.im-tal.net\">maxe<\/a> werden jetzt auch die WordPress Settings ber\u00fccksichtigt (Comment author must fill out name and e-mail) und das &quot;Comment&quot;-Feld ist nat\u00fcrlich auch <code>required<\/code><\/ins><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"php\"><span class=\"hljs-meta\">&lt;?php<\/span>\n<span class=\"hljs-comment\">\/*\nPlugin Name: html5 input-types\nPlugin URI: https:\/\/notiz.blog\/\nDescription: Adds the new HTML5 input-types to WordPress' default forms\nVersion: 0.1\nAuthor: pfefferle\nAuthor URI: https:\/\/notiz.blog\/\n*\/<\/span>\n\nadd_filter(<span class=\"hljs-string\">\"comment_form_default_fields\"<\/span>, <span class=\"hljs-string\">\"change_comment_input_types\"<\/span>);\n\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">change_comment_input_types<\/span><span class=\"hljs-params\">($fields)<\/span> <\/span>{\n  <span class=\"hljs-keyword\">if<\/span> (get_option(<span class=\"hljs-string\">\"require_name_email\"<\/span>, <span class=\"hljs-keyword\">false<\/span>)) {\n    $fields&#91;<span class=\"hljs-string\">'author'<\/span>] = preg_replace(<span class=\"hljs-string\">'\/&lt;input\/'<\/span>, <span class=\"hljs-string\">'&lt;input required'<\/span>, $fields&#91;<span class=\"hljs-string\">'author'<\/span>]);\n    $fields&#91;<span class=\"hljs-string\">'email'<\/span>] = preg_replace(<span class=\"hljs-string\">'\/\"text\"\/'<\/span>, <span class=\"hljs-string\">'\"email\" required'<\/span>, $fields&#91;<span class=\"hljs-string\">'email'<\/span>]);\n  } <span class=\"hljs-keyword\">else<\/span> {\n    $fields&#91;<span class=\"hljs-string\">'email'<\/span>] = preg_replace(<span class=\"hljs-string\">'\/\"text\"\/'<\/span>, <span class=\"hljs-string\">'\"email\"'<\/span>, $fields&#91;<span class=\"hljs-string\">'email'<\/span>]);\n  }\n\n  $fields&#91;<span class=\"hljs-string\">'url'<\/span>] = preg_replace(<span class=\"hljs-string\">'\/\"text\"\/'<\/span>, <span class=\"hljs-string\">'\"url\"'<\/span>, $fields&#91;<span class=\"hljs-string\">'url'<\/span>]);\n\n  <span class=\"hljs-keyword\">return<\/span> $fields;\n}\n\nadd_filter(<span class=\"hljs-string\">\"get_search_form\"<\/span>, <span class=\"hljs-string\">\"change_search_form_input_types\"<\/span>);\n\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">change_search_form_input_types<\/span><span class=\"hljs-params\">($form)<\/span> <\/span>{\n  <span class=\"hljs-keyword\">return<\/span> preg_replace(<span class=\"hljs-string\">'\/\"text\"\/'<\/span>, <span class=\"hljs-string\">'\"search\"'<\/span>, $form);\n}\n\nadd_filter(<span class=\"hljs-string\">\"comment_form_field_comment\"<\/span>, <span class=\"hljs-string\">\"change_comment_field_input_types\"<\/span>);\n\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">change_comment_field_input_types<\/span><span class=\"hljs-params\">($field)<\/span> <\/span>{\n  <span class=\"hljs-keyword\">return<\/span> preg_replace(<span class=\"hljs-string\">'\/&lt;textarea\/'<\/span>, <span class=\"hljs-string\">'&lt;textarea required'<\/span>, $field);\n}\n<span class=\"hljs-meta\">?&gt;<\/span><\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code-Sprache:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Funktioniert als Plugin und in Child-Themes (einfach in die <code>functions.php<\/code> kopieren).<\/p>\n\n\n\n<p>Danke auch an <a href=\"https:\/\/marcgoertz.de\/\">Marc G\u00f6rtz<\/a> der mich \u00fcber <a href=\"http:\/\/twitter.com\/dreamseer\">Twitter<\/a> reichlich mit Links zu dem Thema versorgt hat:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n    <li><a href=\"https:\/\/web.archive.org\/web\/20200724153910\/http:\/\/diveintohtml5.info\/forms.html\">A Form of Madness (den hab ich selber gefunden)<\/a><\/li>\n    <li><a href=\"https:\/\/web.archive.org\/web\/20110307142356\/http:\/\/html5pattern.com\/\">HTML5 Pattern<\/a><\/li>\n    <li><a href=\"https:\/\/web.archive.org\/web\/20100629022438\/http:\/\/flowplayer.org\/tools\/demos\/validator\/index.html\">Fallback jQuery Validator<\/a><\/li>\n<\/ul>\n\n\n\n<p>Testen k\u00f6nnt ihr das \u00fcbrigens hier auf notiz.blog.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Dass HTML5 ein paar neue input-types definiert, habe ich durch die hcard-input-brainstorming so am Rande auf geschnappt, mir aber nichts weiter dabei gedacht&#8230; Durch Zufall bin ich heute aber \u00fcber folgenden Tweet von Sylvia Egger gesto\u00dfen: Just implemented native #HTML5 form validation on #wp comments form &#8211; it&#x27; quite simple &amp; should be in #wp [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"webmentions_disabled_pings":false,"webmentions_disabled":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[946],"tags":[948,5171,166,700,947,181,57],"class_list":{"0":"post-3840","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-wordpress","7":"tag-child-theme","8":"tag-fediblog","9":"tag-hcard","10":"tag-html5","11":"tag-input-types","12":"tag-plugin","13":"tag-wordpress","14":"h-entry","15":"hentry"},"_links":{"self":[{"href":"https:\/\/notiz.blog\/wp-api\/wp\/v2\/posts\/3840","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/notiz.blog\/wp-api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/notiz.blog\/wp-api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/notiz.blog\/wp-api\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/notiz.blog\/wp-api\/wp\/v2\/comments?post=3840"}],"version-history":[{"count":5,"href":"https:\/\/notiz.blog\/wp-api\/wp\/v2\/posts\/3840\/revisions"}],"predecessor-version":[{"id":21637,"href":"https:\/\/notiz.blog\/wp-api\/wp\/v2\/posts\/3840\/revisions\/21637"}],"wp:attachment":[{"href":"https:\/\/notiz.blog\/wp-api\/wp\/v2\/media?parent=3840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/notiz.blog\/wp-api\/wp\/v2\/categories?post=3840"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/notiz.blog\/wp-api\/wp\/v2\/tags?post=3840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}