Bootstrap Formular Validierung

Hier bekommst Du deutschsprachigen Support. Keine Fehlermeldungen oder Erweiterungswünsche bitte!
Post Reply
User avatar
Uwe367
Posts: 1206
Joined: Sat 15. Sep 2007, 07:19
Location: Koblenz

Bootstrap Formular Validierung

Post by Uwe367 »

Hallo allerseits,
Ich bin mir sicher daß ich dieses Thema schonmal in einem anderen Thread aufgegriffen hatte, aber ich finde es nicht mehr. Daher greife ich es jetzt nochmals auf. Wie die Überschrift schon sagt geht es um die Bootstrap Formular Validierung, welche ich persönlich sehr schön finde.

Jedoch ist der CP Formular so aufgebaut daß ich die Bootstrapklassen nicht verwenden kann, was aber wohl notwendig wäre wie man hier sehen kann.
Ich muß irgendwie <form class="needs-validation" novalidate> generiert bekommen, jedoch gestaltet sich das als nicht möglich da von phpwcms ein form- vor die Klasse gesetzt wenn ich im CP im Feld Formular CSS Class diese Klasse eintrage. Das Resultat dannform-needs-validation ist und das funktioniert nicht. Zudem wird durch diese Klasse automatisch nochmal ein DIV um das form TAG gelegt so daß der Quellcode dann so aussieht. Als Beispielklasse habe ich .myclass verwendet.

Code: Select all

<div class="myclass"><form id="phpwcmsForm1" class="form-myclass" action="http://localhost/form/#jumpForm1" method="post">
Entferne ich die Klasse .myclass, sieht es so aus:

Code: Select all

<form id="phpwcmsForm1" action="http://localhost/form/#jumpForm1" method="post">
Warum da nochmal ein DIV mit der gleichen Klasse um das Form TAG gelegt wird weiß ich nicht, aber Oliver wird sich da sicher etwas bei gedacht haben. Eventuell arbeitet nicht jeder mit dem Custom Template und dann macht das ja auch wieder Sinn.
Vielleicht wäre es aber sinnvoller das über die conf.template_default.inc.php zu steuern so daß dort eine beliebige Klasse verwendet werden kann, unabhängig von dem was ich im CP bei Formular CSS Class eintrage.

Aber zurück zum Feld Formular CSS Class.
Ich habe mal gesucht und auch gefunden.
Verzeichnis include/inc_front/content/cnt23.article.inc.php bei Zeile 2418 wird ein DIV erzeugt welches das form TAG umschließt und bei Zeile 2420 wird der Klasse das form- voran gesetzt.

Könnte man da mittels frontend Render Script eingreifen oder würdest du das im Core ändern wollen Oliver?
Irgendwie erschließt sich mir der Sinn nicht warum bei der Formular CSS Class das form- voran gesetzt und somit die eingetragene Klasse unbrauchbar wird....

Es handelt sich dabei um dieses Feld im CP Forumlar:
Image

Vielleicht kann mal jemand Licht ins Dunkel bringen :D

[EDIT]
Hat sich erledigt. Das vorherige war ein Issue und Oliver hat dort bereits einen Lösungsansatz gepostet. Wird nicht geändert da das Probleme mit älteren Installationen geben könnte. Verständlich.

Leider erzeugt jedoch das php Script, welches Oliver bei Github gepostet hatte, einen Fehler wen ich es in frontend_render lege:
Parse error: syntax error, unexpected 'form' (T_STRING), expecting ']' in D:\xampp\htdocs\form\template\inc_script\frontend_render\form.php on line 2

Sscript:

Code: Select all

<?php 
$content['all] = str_replace('form-novalidate"', 'needs-validation" novalidate');
?>
Kann da jemand helfen?
[/EDIT]
User avatar
top
Posts: 535
Joined: Fri 11. Aug 2006, 15:03
Location: Eutin

Re: Bootstrap Formular Validierung

Post by top »

Uwe367 wrote: Sun 17. May 2020, 19:20 ...
Sscript:

Code: Select all

<?php 
$content['all] = str_replace('form-novalidate"', 'needs-validation" novalidate');
?>
Kann da jemand helfen?
[/EDIT]
Fehlt da vielleicht hier etwas?
$content['all'] ...
User avatar
Uwe367
Posts: 1206
Joined: Sat 15. Sep 2007, 07:19
Location: Koblenz

Re: Bootstrap Formular Validierung

Post by Uwe367 »

top wrote: Mon 18. May 2020, 10:18 Fehlt da vielleicht hier etwas?
$content['all'] ...
Ne, das hatte ich schon probiert und das fühtr dann zu einer neuen Fehlermeldung:

Code: Select all

Warning: str_replace() expects at least 3 parameters, 1 given in D:\xampp\htdocs\form\template\inc_script\frontend_render\fom.php on line 2
Aber trotzdem Danke :)
User avatar
top
Posts: 535
Joined: Fri 11. Aug 2006, 15:03
Location: Eutin

Re: Bootstrap Formular Validierung

Post by top »

Gerade mal geschaut wie das bei den Scripten aussieht die bei mir funktionieren. So müsste es bei dir eigentlich laufen:

Code: Select all

<?php
$content['all'] = str_replace('form-novalidate"', 'needs-validation" novalidate', $content['all']);
Ach ja, wenn ich mich nicht irre, soll am Ende der Datei dann auch kein abschließendes ?> stehen!
User avatar
Uwe367
Posts: 1206
Joined: Sat 15. Sep 2007, 07:19
Location: Koblenz

Re: Bootstrap Formular Validierung

Post by Uwe367 »

top wrote: Tue 19. May 2020, 10:32

Code: Select all

<?php
$content['all'] = str_replace('form-novalidate"', 'needs-validation" novalidate', $content['all']);
Jau, das wars und nun läufts. Danke dir vielmals.
So ähnlich hatte ich das Script auch schon aber wohl doch noch nicht so ganz richtig.
Habe das nun noch etwas erweitert damit ich dem DIV, welches das form TAG umschließt, auch noch eine eigene Klasse mitgeben kann und nun sieht das ganze so aus:

Code: Select all

<?php
// -------------------------------------------------------------------------------------------
// obligate check for phpwcms constants
  if (!defined('PHPWCMS_ROOT')) {
    die("You Cannot Access This Script Directly, Have a Nice Day."); }
// -------------------------------------------------------------------------------------------
$content['all'] = str_replace('form-needs-validation"', 'needs-validation" novalidate', $content['all']);
$content['all'] = str_replace('div class="needs-validation"', 'div class="myclass"', $content['all']);
So bleibt die Klasse, die ich benötige, erhalten und das umschließende DIV bekommt hier die Beispielklasse .myclass.

Danke dir nochmals :D
Post Reply