Hi,
kann mir jemand sagen, welches Template für ein Formular verwendet wird und wie ich nur für ein
bestimmtes Formular ein eigenes Template einbinden kann?
Danke
Gruß
Michel
Hi,
kann mir jemand sagen, welches Template für ein Formular verwendet wird und wie ich nur für ein
bestimmtes Formular ein eigenes Template einbinden kann?
Danke
Gruß
Michel
Hallo,
Hast Du zufällig mittlerweile herausgefunden, wie man einem Formular ein eigenes Template zuweisen kann?
Gruß
Das template heisst form_widget, oder einfach form.html5/xhtml/tpl
Das findet man im Ordner /system/modules/frontend/templates
Tim
http://www.tim-gatzky.de ˙ auch schon wieder 2 Jahre alt - wie die Zeit vergeht... muss mal umbauen.
Hallo Tim,
Danke - aber wird das dann nicht für alle Formulare verwendet? Wie kann ich das genau einem Formular zuweisen?
Gruß
Im Template eine Unterscheidung per Formular-ID machen ist sicher der beste Weg.
Das sehe dann so aus:
PHP-Code:
<?php if( $this->formID == 'contactform' ): ?>
Das Template für das Formular mit der Formular-ID [I]contactform[/I] hiere
<?php else: ?>
Das Standard-Template hier
<?php endif; ?>
http://www.tim-gatzky.de ˙ auch schon wieder 2 Jahre alt - wie die Zeit vergeht... muss mal umbauen.
Ok verstehe - das Template wird zwar für alle angewendet, aber es wird eine Fallunterscheidung nach dem FormID gemacht.
Nachtrag: Klasse klapp!PHP-Code:
<?php if( $this->formID == 'preisanfrage' ): ?>
<!-- indexer::stop -->
<div class="<?php echo $this->class; ?> <?php echo $this->tableless ? 'tableless' : 'tableform'; ?> block"<?php echo $this->cssID; ?><?php if ($this->style): ?> style="<?php echo $this->style; ?>"<?php endif; ?>>
<?php if ($this->headline): ?>
<<?php echo $this->hl; ?>><?php echo $this->headline; ?></<?php echo $this->hl; ?>>
<?php endif; ?>
<form action="<?php echo $this->action; ?>" id="<?php echo $this->formId; ?>" method="<?php echo $this->method; ?>" enctype="<?php echo $this->enctype; ?>"<?php echo $this->attributes; ?>>
<div class="formbody">
<?php if ($this->method != 'get'): ?>
<input type="hidden" name="FORM_SUBMIT" value="<?php echo $this->formSubmit; ?>">
<input type="hidden" name="REQUEST_TOKEN" value="{{request_token}}">
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $this->maxFileSize; ?>">
<input type="hidden" name="Productname" value="<?php echo $this->name; ?>">
<?php endif; ?>
<?php echo $this->hidden; ?>
<?php if (!$this->tableless): ?>
<table>
<?php echo $this->fields; ?>
</table>
<?php else: echo $this->fields; endif; ?>
</div>
</form>
<?php if ($this->hasError): ?>
<script>
try {
window.scrollTo(null, ($('<?php echo $this->formId; ?>').getElement('p.error').getPosition().y - 20));
} catch(e) {}
</script>
<?php endif; ?>
</div>
<!-- indexer::continue -->
<?php else: ?>
<!-- indexer::stop -->
<div class="<?php echo $this->class; ?> <?php echo $this->tableless ? 'tableless' : 'tableform'; ?> block"<?php echo $this->cssID; ?><?php if ($this->style): ?> style="<?php echo $this->style; ?>"<?php endif; ?>>
<?php if ($this->headline): ?>
<<?php echo $this->hl; ?>><?php echo $this->headline; ?></<?php echo $this->hl; ?>>
<?php endif; ?>
<form action="<?php echo $this->action; ?>" id="<?php echo $this->formId; ?>" method="<?php echo $this->method; ?>" enctype="<?php echo $this->enctype; ?>"<?php echo $this->attributes; ?>>
<div class="formbody">
<?php if ($this->method != 'get'): ?>
<input type="hidden" name="FORM_SUBMIT" value="<?php echo $this->formSubmit; ?>">
<input type="hidden" name="REQUEST_TOKEN" value="{{request_token}}">
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $this->maxFileSize; ?>">
<?php endif; ?>
<?php echo $this->hidden; ?>
<?php if (!$this->tableless): ?>
<table>
<?php echo $this->fields; ?>
</table>
<?php else: echo $this->fields; endif; ?>
</div>
</form>
<?php if ($this->hasError): ?>
<script>
try {
window.scrollTo(null, ($('<?php echo $this->formId; ?>').getElement('p.error').getPosition().y - 20));
} catch(e) {}
</script>
<?php endif; ?>
</div>
<!-- indexer::continue -->
<?php endif; ?>
Geändert von bintux (17.03.2012 um 14:09 Uhr)
Eine Frage habe ich noch, wie kann ich die Informationen der hidden Felder in der Email, die versendet wird, mit aufführen?
Was meinst du mit "mit aufführen". Sollen die sichtbar sein?
Da gibts mehrere Möglichkeiten, je nach dem was damit passieren soll. Kommt ja pro verstecktem Feld ein html String an. Den kannst du ja beliebig manipulieren.
Hier eine Variante einfach als neues Input field.
PHP-Code:
<?php echo str_replace('type="hidden"', 'type="text"', $this->hidden); ?>
http://www.tim-gatzky.de ˙ auch schon wieder 2 Jahre alt - wie die Zeit vergeht... muss mal umbauen.
Hallo Tim,
Erstmal viel Dank für Deine Hilfe.
Ich meinte mit Aufführen, dass der Value Wert des hidden Feldes mit in der EMail erscheint, die bei die eingestellte Adresse versendet wird.
Ich habe aber festgestellt, das mein Versuch sowieso noch nicht ganz funktioniert. Ich habe den Isotope Produktleser in meinem Artikel eingebunden und direkt darunter das erwähnte Formular. Ich wollte jetzt erreichen, dass der Produktname im Formular automatisch erfasst und mit verschickt wird.
Ich habe also im Formular ein hidden Feld angelegt mitum den Produktnamen vom Reader Modul zu holen. Leider klappt das nicht. Weißt du wie ich von einem zum nächsten Inhaltselement die Variable übergeben kann? Ginge als Alternative vielleicht ein Formular in das Product Reader Template einzubauen?PHP-Code:
value="<?php echo $this->name; ?>"
Viele Grüße und einen schönen Sonntag noch.
Eike
$this hat standardmäßig immer den Bezug zum jeweiligen Objekt. Hier das Template-Objekt.
Innerhalb des Produktlesers Template ein Formular würde funktionieren.
Wird der Produktleser vor dem Formular geladen, könnte man auch eine globale Variable nutzen, um die Felder zu beschreiben.
Du kannst aber auch den mit Datenbankabfragen an einen Wert kommen, falls dieser in der Datenbank gespeichert ist.
http://www.tim-gatzky.de ˙ auch schon wieder 2 Jahre alt - wie die Zeit vergeht... muss mal umbauen.
Entschuldige bitte meine Unwissenheit
Also der Isotope Produktleser wird vor dem Formular eingelesen. Wie würde den die globale Variable funktionieren? Muss ich im Produktleser Template die "lokale" Variable einer globalen zuweisen?
Gruß Eike
Hallo Tim
Ich wollte jetzt eine globale Variable eintragen wie hier von Dir beschrieben https://www.contao-community.de/show...obale+variable aber jetzt verwendet Contao für die Formulare nicht mehr mein Template? Ich habe es schon gelöscht und ein neues angelegt aber es wird nicht verwendet?
Vergiss den anderen Thread. Da ging es um Theme_plus Variablen.
Hier die Schritte.
1. Initialisier die neue Variable in z.b. der localconfig, oder dcaconfig.php. im $GLOBALS Array. z.B. $GLOBALS['MEINE_VARIABLE'] = 'Hallo'; // String
Die Tiefe es Array kannst du selbst bestimmen und den Typen. Könnte ja auch ein weiterer array sein. Das bestimmst du.
2. Im Produktleser beschreibst du diese Variable mit dem gewünschten Wert. so wie oben 'Hallo'.
3. Im Formular kannst du die dann auslesen. mit echo, oder ausgeben via print. Was auch immer. Im hidden field würde das so aussehen
<input type="hidden" value="<?php echo $GLOBALS['MEINE_VARIABLE']; ?>">
Grüße
ps. dieser Weg klappt nur, weil das Formular nach dem Produktleser geladen wird!
http://www.tim-gatzky.de ˙ auch schon wieder 2 Jahre alt - wie die Zeit vergeht... muss mal umbauen.
Hallo Tim,
So ich habe das jetzt mal probiert, aber irgendwo mach ich ich noch was falsch.
In dcaconfig.php eingetragen:
Dann im Productleser noch mal eingetragenPHP-Code:
$GLOBALS['PRODUCT_NAME'] = 'Product';
Im Productleser gibt er mir bei echo auch den Produktnamen aus, aber im Formular ist leider nur Product zu lesen, also was ich in der dcaconfig.php gesetzt habe.PHP-Code:
<?php $GLOBALS['PRODUCT_NAME'] = "$this->name"; ?>
Eigentlich brauchst du in der dcaconfig nichts setzen. Da reicht das initialisieren. Aber zum Test ist ja erstmal nicht falsch.
1.
<?php $GLOBALS['PRODUCT_NAME'] = "$this->name"; ?> <- ohne Anführungsstriche hier.
<?php $GLOBALS['PRODUCT_NAME'] = $this->name; ?>
2. Wenn du am Anfang des Templates echo $GLOBALS['PRODUCT_NAME'] aufrufst, gibt er Dir natürlich den Wert aus der Initialiserung.
Der neue Wert ist natürlich erst nach dem Aufruf. <?php $GLOBALS['PRODUCT_NAME'] = $this->name; ?> beschrieben.
3. Jetzt kannst du in dein Formular-Template wechseln und dort nochmal mit echo die Variable auslesen. Dort sollte dann der Wert von $this->name; aus dem Produktleser Template reinkommen.
Das alles funktioniert natürlich auch nur auf einer Seite! Also Formular und Leser befinden sich auf einer Seite. In PHP gibt es keine Sandbox und damit wirkliche Globale wie in z.B. Flash.
Musst du die Variable über mehrere Seiten wissen hilft nur cookie, session oder in die Datenbank damit.
Grüße
http://www.tim-gatzky.de ˙ auch schon wieder 2 Jahre alt - wie die Zeit vergeht... muss mal umbauen.
Danke Dir, das klappt!
Hat jetzt etwas gedauert, denn ich musste erst lernen, dass auch zwischen dem Inhaltselementen Produktleser und dem Formular kein anderes Inhaltselement stehen darf. - Ich hatte dazwischen erst noch ein anderes Inhaltselement.
Jetzt bleibt noch ein Problem - mein form.html5 Template wird nicht mehr ausgelesen. Ich habe stellvertretend die Variable mit einem anderem Inhaltselement getestet. Aber jetzt will ich es ja im Formular haben.
Das Template form.html5, das kurz ging wird jetzt nicht mehr beachtet. Hast du vielleicht eine Idee?
Ich habe in dem Template eine Kontrolle eingebaut, ob die anderen Formulare ohne die ID==preisanfrage davon beeinflusst werden, aber die Kontrolle taucht auch da nicht auf.
Vielen Dank für Deine Hilfe!
Hier noch mal meine form.html5
PHP-Code:
<?php if( $this->formID == 'preisanfrage' ): ?>
<!-- indexer::stop -->
<div class="<?php echo $this->class; ?> <?php echo $this->tableless ? 'tableless' : 'tableform'; ?> block"<?php echo $this->cssID; ?><?php if ($this->style): ?> style="<?php echo $this->style; ?>"<?php endif; ?>>
<?php if ($this->headline): ?>
<<?php echo $this->hl; ?>><?php echo $this->headline; ?></<?php echo $this->hl; ?>>
<?php endif; ?>
<form action="<?php echo $this->action; ?>" id="<?php echo $this->formId; ?>" method="<?php echo $this->method; ?>" enctype="<?php echo $this->enctype; ?>"<?php echo $this->attributes; ?>>
<div class="formbody">
<?php if ($this->method != 'get'): ?>
<input type="hidden" name="FORM_SUBMIT" value="<?php echo $this->formSubmit; ?>">
<input type="hidden" name="REQUEST_TOKEN" value="{{request_token}}">
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $this->maxFileSize; ?>">
<input type="hidden" name="Productname" value="<?php echo $this->name; ?>">
<?php endif; ?>
<?php echo $this->hidden; ?>
<?php if (!$this->tableless): ?>
<table>
<?php echo $this->fields; ?>
</table>
<?php else: echo $this->fields; endif; ?>
</div>
</form>
<?php if ($this->hasError): ?>
<script>
try {
window.scrollTo(null, ($('<?php echo $this->formId; ?>').getElement('p.error').getPosition().y - 20));
} catch(e) {}
</script>
<?php endif; ?>
</div>
<!-- indexer::continue -->
<?php else: ?>
<!-- indexer::stop -->
<div class="<?php echo $this->class; ?> <?php echo $this->tableless ? 'tableless' : 'tableform'; ?> block"<?php echo $this->cssID; ?><?php if ($this->style): ?> style="<?php echo $this->style; ?>"<?php endif; ?>>
<?php if ($this->headline): ?>
<<?php echo $this->hl; ?>><?php echo $this->headline; ?></<?php echo $this->hl; ?>>
<?php endif; ?>
<form action="<?php echo $this->action; ?>" id="<?php echo $this->formId; ?>" method="<?php echo $this->method; ?>" enctype="<?php echo $this->enctype; ?>"<?php echo $this->attributes; ?>>
<div class="formbody">
<?php if ($this->method != 'get'): ?>
<input type="hidden" name="FORM_SUBMIT" value="<?php echo $this->formSubmit; ?>">
<input type="hidden" name="REQUEST_TOKEN" value="{{request_token}}">
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $this->maxFileSize; ?>">
<input type="hidden" name="kontrolle" value="dies ist die kontrolle">
<?php endif; ?>
<?php echo $this->hidden; ?>
<?php if (!$this->tableless): ?>
<table>
<?php echo $this->fields; ?>
</table>
<?php else: echo $this->fields; endif; ?>
</div>
</form>
<?php if ($this->hasError): ?>
<script>
try {
window.scrollTo(null, ($('<?php echo $this->formId; ?>').getElement('p.error').getPosition().y - 20));
} catch(e) {}
</script>
<?php endif; ?>
</div>
<!-- indexer::continue -->
<?php endif; ?>
im input field value musst du jetzt auch deine globale Variable eintragen.
Da steht noch $this->name;
Sollte aber eigentlich an der Funktion nichts ändern.
Eigentlich sollte es auch egal sein ob ein Element dazwischen ist.
http://www.tim-gatzky.de ˙ auch schon wieder 2 Jahre alt - wie die Zeit vergeht... muss mal umbauen.
Klar - ich Trottel. Habs geändert, aber beim Formular wird der Wert nicht ausgegeben. Das andere Inhaltselement (Ich habe eine Loginmodul zweckentfremdet) gibt die Variable aus. ??
PHP-Code:
<?php if( $this->formID == 'preisanfrage' ): ?>
<!-- indexer::stop -->
<div class="<?php echo $this->class; ?> <?php echo $this->tableless ? 'tableless' : 'tableform'; ?> block"<?php echo $this->cssID; ?><?php if ($this->style): ?> style="<?php echo $this->style; ?>"<?php endif; ?>>
<?php if ($this->headline): ?>
<<?php echo $this->hl; ?>><?php echo $this->headline; ?></<?php echo $this->hl; ?>>
<?php endif; ?>
<form action="<?php echo $this->action; ?>" id="<?php echo $this->formId; ?>" method="<?php echo $this->method; ?>" enctype="<?php echo $this->enctype; ?>"<?php echo $this->attributes; ?>>
<div class="formbody">
<?php if ($this->method != 'get'): ?>
<input type="hidden" name="FORM_SUBMIT" value="<?php echo $this->formSubmit; ?>">
<input type="hidden" name="REQUEST_TOKEN" value="{{request_token}}">
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $this->maxFileSize; ?>">
<input type="hidden" name="Productname" value="<?php print $GLOBALS['PRODUCT_NAME']?>">
<p>Test:<?php echo $GLOBALS['PRODUCT_NAME']?></p>
<?php endif; ?>
<?php echo $this->hidden; ?>
<?php if (!$this->tableless): ?>
<table>
<?php echo $this->fields; ?>
</table>
<?php else: echo $this->fields; endif; ?>
</div>
</form>
<?php if ($this->hasError): ?>
<script>
try {
window.scrollTo(null, ($('<?php echo $this->formId; ?>').getElement('p.error').getPosition().y - 20));
} catch(e) {}
</script>
<?php endif; ?>
</div>
<!-- indexer::continue -->
<?php else: ?>
<!-- indexer::stop -->
<div class="<?php echo $this->class; ?> <?php echo $this->tableless ? 'tableless' : 'tableform'; ?> block"<?php echo $this->cssID; ?><?php if ($this->style): ?> style="<?php echo $this->style; ?>"<?php endif; ?>>
<?php if ($this->headline): ?>
<<?php echo $this->hl; ?>><?php echo $this->headline; ?></<?php echo $this->hl; ?>>
<?php endif; ?>
<form action="<?php echo $this->action; ?>" id="<?php echo $this->formId; ?>" method="<?php echo $this->method; ?>" enctype="<?php echo $this->enctype; ?>"<?php echo $this->attributes; ?>>
<div class="formbody">
<?php if ($this->method != 'get'): ?>
<input type="hidden" name="FORM_SUBMIT" value="<?php echo $this->formSubmit; ?>">
<input type="hidden" name="REQUEST_TOKEN" value="{{request_token}}">
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $this->maxFileSize; ?>">
<input type="hidden" name="kontrolle" value="dies ist die kontrolle">
<?php endif; ?>
<?php echo $this->hidden; ?>
<?php if (!$this->tableless): ?>
<table>
<?php echo $this->fields; ?>
</table>
<?php else: echo $this->fields; endif; ?>
</div>
</form>
<?php if ($this->hasError): ?>
<script>
try {
window.scrollTo(null, ($('<?php echo $this->formId; ?>').getElement('p.error').getPosition().y - 20));
} catch(e) {}
</script>
<?php endif; ?>
</div>
<!-- indexer::continue -->
<?php endif; ?>
Was schreibst du denn da?
Print und p tags im value Attribut vom input feld???
Nur echo nutzen!
Nicht das nächste Inhaltselement gibt den Wert aus, sondern das print und das ist falsch.
Den Wert erhält man nach dem Absenden via {{form::FELDNAME}}
den kannst du im Text einfach benutzen.
http://www.tim-gatzky.de ˙ auch schon wieder 2 Jahre alt - wie die Zeit vergeht... muss mal umbauen.
Hem ok - ich dachte Input war schon wieder geschlossen.
Ich habe es auf echo geändert, aber value bleibt leer.
PHP-Code:
<?php if( $this->formID == 'preisanfrage' ): ?>
<!-- indexer::stop -->
<div class="<?php echo $this->class; ?> <?php echo $this->tableless ? 'tableless' : 'tableform'; ?> block"<?php echo $this->cssID; ?><?php if ($this->style): ?> style="<?php echo $this->style; ?>"<?php endif; ?>>
<?php if ($this->headline): ?>
<<?php echo $this->hl; ?>><?php echo $this->headline; ?></<?php echo $this->hl; ?>>
<?php endif; ?>
<form action="<?php echo $this->action; ?>" id="<?php echo $this->formId; ?>" method="<?php echo $this->method; ?>" enctype="<?php echo $this->enctype; ?>"<?php echo $this->attributes; ?>>
<div class="formbody">
<?php if ($this->method != 'get'): ?>
<input type="hidden" name="FORM_SUBMIT" value="<?php echo $this->formSubmit; ?>">
<input type="hidden" name="REQUEST_TOKEN" value="{{request_token}}">
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $this->maxFileSize; ?>">
<input type="hidden" name="Productname" value="<?php echo $GLOBALS['PRODUCT_NAME'] ?>">
<?php endif; ?>
<?php echo $this->hidden; ?>
<?php if (!$this->tableless): ?>
<table>
<?php echo $this->fields; ?>
</table>
<?php else: echo $this->fields; endif; ?>
</div>
</form>
<?php if ($this->hasError): ?>
<script>
try {
window.scrollTo(null, ($('<?php echo $this->formId; ?>').getElement('p.error').getPosition().y - 20));
} catch(e) {}
</script>
<?php endif; ?>
</div>
<!-- indexer::continue -->
<?php else: ?>
<!-- indexer::stop -->
<div class="<?php echo $this->class; ?> <?php echo $this->tableless ? 'tableless' : 'tableform'; ?> block"<?php echo $this->cssID; ?><?php if ($this->style): ?> style="<?php echo $this->style; ?>"<?php endif; ?>>
<?php if ($this->headline): ?>
<<?php echo $this->hl; ?>><?php echo $this->headline; ?></<?php echo $this->hl; ?>>
<?php endif; ?>
<form action="<?php echo $this->action; ?>" id="<?php echo $this->formId; ?>" method="<?php echo $this->method; ?>" enctype="<?php echo $this->enctype; ?>"<?php echo $this->attributes; ?>>
<div class="formbody">
<?php if ($this->method != 'get'): ?>
<input type="hidden" name="FORM_SUBMIT" value="<?php echo $this->formSubmit; ?>">
<input type="hidden" name="REQUEST_TOKEN" value="{{request_token}}">
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $this->maxFileSize; ?>">
<input type="hidden" name="kontrolle" value="dies ist die kontrolle">
<?php endif; ?>
<?php echo $this->hidden; ?>
<?php if (!$this->tableless): ?>
<table>
<?php echo $this->fields; ?>
</table>
<?php else: echo $this->fields; endif; ?>
</div>
</form>
<?php if ($this->hasError): ?>
<script>
try {
window.scrollTo(null, ($('<?php echo $this->formId; ?>').getElement('p.error').getPosition().y - 20));
} catch(e) {}
</script>
<?php endif; ?>
</div>
Da müsste sogar ein php Fehler kommen, weil nach der Variablen nicht mit ; geschlossen ist.
http://www.tim-gatzky.de ˙ auch schon wieder 2 Jahre alt - wie die Zeit vergeht... muss mal umbauen.
Ich habe hinter der Variablen jetzt geschlossen, aber leider geht es immer noch nicht.
Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
Lesezeichen