Inhalt eines Cookies in Webform anzeigen
Eingetragen von Carla (18)
am 29.10.2015 - 12:12 Uhr in
am 29.10.2015 - 12:12 Uhr in
Hallo,
ich möchte den Inhalt eines Cookies, wenn er schon gesetzt ist, als Wert in einem Webform Formular anzeigen.
Nachdem ersten Absenden des Formulars wird eine webform-confirmation-x.tpl.php angezeigt. Die setzt auch den Cookie. Testausgabe des Cookies auf der gleichen Seite ergibt jeweils die letzte Eingabe.
Code:
user_cookie_save(array('name'=>($submission->data[3][0])));
print $_COOKIE['Drupal_visitor_name']; //outputs value
Wenn dieses oder ein anderes Formular (es werden ca. 70) den angegebenen Namen benötigt, soll der Name als Default Value in dem Formular stehen.
Wie erreiche ich das?
Vielen Dank für Eure Mühe
Carla
- Anmelden oder Registrieren um Kommentare zu schreiben
Ich würde zu diesem Zwecke
am 29.10.2015 - 13:39 Uhr
Ich würde zu diesem Zwecke ein kleines Modul schreiben, das hook_form_alter implementiert, darin das Cookie ausliest und das Feld vorbesetzt.
.
Werner
drupal-training.de
Moderator und Drupal Trainer
* - - - - - - - - - - - - - - - - - - - - - - - - - - - *
Inhalt eines Cookies in Webform anzeigen
am 22.11.2015 - 12:00 Uhr
Hallo , ich habe den obigen Rat befolgt und mein erstes Modul geschrieben.
In webform_cookies.module ist folgende Funktion.
<?php
/*
* Implementation of hook_form_alter()
*/
function webform_cookies_form_alter(&$form, &$form_state, $form_id){
drupal_set_message("Cookie: " . $_COOKIE['Drupal_visitor_name']);
}
?>
Das funktioniert für jeden Node auf der Seite, d.h. das Modul wird erkannt.
Jetzt ist mir aber nicht klar, wie ich auf den Formularseiten mit dem Component "name_des_kindes" den Cookie-Wert als default erscheinen lasse. Mir schwebt Folgendes vor:
function webform_cookies_form_alter(&$form, &$form_state, $form_id){
if ( $_COOKIE['Drupal_visitor_name']&& $form['name_des_kindes']){
$form['name_des_kindes']['value'] = $_COOKIE['Drupal_visitor_name'];
}
}
Das führt aber für jeden node zu folgender Fehlermeldung.
Notice: Undefined index: name_des_kindes in webform_cookies_form_alter() (line 7 of C:\xampp\htdocs\mysites\drupal\sites\all\modules\webform_cookies\webform_cookies.module).
Wie spreche ich die Felder eines Formulars in einem hook richtig an?
Vielen Dank für Eure Mühe
Carla
Carla schrieb Wie spreche ich
am 22.11.2015 - 15:05 Uhr
Wie spreche ich die Felder eines Formulars in einem hook richtig an?
du musst dir zunächst einmal die Struktur des Form- Arrays ansehen. Wenn du keine IDE mit Debugger benutzt, am Besten das Devel Modul installieren. Dann kannst du dir mit dpm($form); innerhalb des form alter hooks die Formular Array- Struktur genau ausgeben lassen. Da wirst du dann so etwas wie
<?php
$form['name_des_kindes']['und'][0]['#default_value'] = $_COOKIE['Drupal_visitor_name'];
?>
setzen können.
Cookie in Webform als default value anzeigen
am 01.12.2015 - 11:15 Uhr
Hallo, leider funktioniert das immer noch nicht.
dpm($webform) gibt folgende Fehlermeldung:
Notice: Undefined variable: webform in webform_cookies_form_alter() (line 13 of C:\xampp\htdocs\mysites\drupal\sites\all\modules\webform_cookies\webform_cookies.module)
Devel zeigt diese Struktur an:
Direkt zum Inhalt
Options for the administrative overlay
If you have problems accessing administrative pages on this site, disable the overlay on your profile page. Dismiss this message.
Rätsel der Amsel
Close overlay
Haupt-Reiter
Ansicht
Bearbeiten
Webform
Resultate
Devel(aktiver Reiter)
Coridola.de
Langeweile ade!
Ansicht
Bearbeiten
Webform
Resultate
Devel(aktiver Reiter)
Load(aktiver Reiter)
Tokens
Render
Sie sind hier
1. Rätsel der Amsel
Rätsel der Amsel
... (Object) stdClass
vid (String, 2 characters ) 24
uid (String, 1 characters ) 1
title (String, 17 characters ) Rätsel der Amsel
log (String, 0 characters )
status (String, 1 characters ) 1
comment (String, 1 characters ) 1
promote (String, 1 characters ) 0
sticky (String, 1 characters ) 0
nid (String, 2 characters ) 24
type (String, 21 characters ) webform_lesen_stufe_2
language (String, 2 characters ) de
created (String, 10 characters ) 1435467630
changed (String, 10 characters ) 1445854762
tnid (String, 1 characters ) 0
translate (String, 1 characters ) 0
revision_timestamp (String, 10 characters ) 1445854762
revision_uid (String, 1 characters ) 1
rdf_mapping (Array, 9 elements)
rdftype (Array, 2 elements)
0 (String, 9 characters ) sioc:Item
1 (String, 13 characters ) foaf:Document
title (Array, 1 element)
predicates (Array, 1 element)
0 (String, 8 characters ) dc:title
created (Array, 3 elements)
predicates (Array, 2 elements)
0 (String, 7 characters ) dc:date
1 (String, 10 characters ) dc:created
datatype (String, 12 characters ) xsd:dateTime
callback (String, 12 characters ) date_iso8601 | (Callback) date_iso8601();
changed (Array, 3 elements)
predicates (Array, 1 element)
0 (String, 11 characters ) dc:modified
datatype (String, 12 characters ) xsd:dateTime
callback (String, 12 characters ) date_iso8601 | (Callback) date_iso8601();
body (Array, 1 element)
predicates (Array, 1 element)
0 (String, 15 characters ) content:encoded
uid (Array, 2 elements)
predicates (Array, 1 element)
0 (String, 16 characters ) sioc:has_creator
type (String, 3 characters ) rel
name (Array, 1 element)
predicates (Array, 1 element)
0 (String, 9 characters ) foaf:name
comment_count (Array, 2 elements)
predicates (Array, 1 element)
0 (String, 16 characters ) sioc:num_replies
datatype (String, 11 characters ) xsd:integer
last_activity (Array, 3 elements)
predicates (Array, 1 element)
0 (String, 23 characters ) sioc:last_activity_date
datatype (String, 12 characters ) xsd:dateTime
callback (String, 12 characters ) date_iso8601 | (Callback) date_iso8601();
webform (Array, 35 elements)
nid (String, 2 characters ) 24
next_serial (String, 3 characters ) 103
confirmation (String, 0 characters )
confirmation_format (String, 8 characters ) php_code
redirect_url (String, 14 characters )
status (String, 1 characters ) 1
block (String, 1 characters ) 0
allow_draft (String, 1 characters ) 0
auto_save (String, 1 characters ) 0
submit_notice (String, 1 characters ) 1
submit_text (String, 17 characters ) Rätsel erstellen
submit_limit (String, 2 characters ) -1
submit_interval (String, 2 characters ) -1
total_submit_limit (String, 2 characters ) -1
total_submit_interval (String, 2 characters ) -1
progressbar_bar (String, 1 characters ) 1
progressbar_page_number (String, 1 characters ) 0
progressbar_percent (String, 1 characters ) 0
progressbar_pagebreak_labels (String, 1 characters ) 1
progressbar_include_confirmation (String, 1 characters ) 1
progressbar_label_first (String, 5 characters ) Start
progressbar_label_confirmation (String, 8 characters ) Complete
preview (String, 1 characters ) 0
preview_next_button_label (String, 0 characters )
preview_prev_button_label (String, 0 characters )
preview_title (String, 0 characters )
preview_message (String, 0 characters )
preview_message_format (String, 13 characters ) filtered_html
preview_excluded_components (Array, 0 elements)
confidential (String, 1 characters ) 0
record_exists (Boolean) TRUE
roles (Array, 2 elements)
0 (String, 1 characters ) 1
1 (String, 1 characters ) 2
emails (Array, 0 elements)
components (Array, 6 elements)
3 (Array, 11 elements)
$...->webform['components'][3]
nid (Integer) 24
cid (String, 1 characters ) 3
pid (String, 1 characters ) 0
form_key (String, 15 characters ) name_des_kindes
$...->webform['components'][3]['form_key']
name (String, 15 characters ) Name des Kindes
$...->webform['components'][3]['name']
type (String, 9 characters ) textfield
$...->webform['components'][3]['type']
value (String, 0 characters )
$...->webform['components'][3]['value']
extra (Array, 14 elements)
title_display (String, 6 characters ) before
private (Integer) 0
wrapper_classes (String, 0 characters )
css_classes (String, 0 characters )
width (String, 0 characters )
maxlength (String, 0 characters )
field_prefix (String, 0 characters )
field_suffix (String, 0 characters )
disabled (Integer) 0
unique (Integer) 0
description (String, 0 characters )
placeholder (String, 0 characters )
attributes (Array, 0 elements)
analysis (Boolean) FALSE
required (String, 1 characters ) 1
weight (String, 1 characters ) 2
page_num (Integer) 1
1 (Array, 11 elements)
nid (Integer) 24
cid (String, 1 characters ) 1
pid (String, 1 characters ) 0
form_key (String, 3 characters ) ort
name (String, 3 characters ) Ort
type (String, 9 characters ) textfield
value (String, 0 characters )
extra (Array, 14 elements)
description (String, 18 characters ) Wohnort des Kindes
title_display (String, 6 characters ) inline
private (Integer) 0
wrapper_classes (String, 0 characters )
css_classes (String, 0 characters )
width (String, 0 characters )
maxlength (String, 0 characters )
field_prefix (String, 0 characters )
field_suffix (String, 0 characters )
disabled (Integer) 0
unique (Integer) 0
placeholder (String, 0 characters )
attributes (Array, 0 elements)
analysis (Boolean) FALSE
required (String, 1 characters ) 1
weight (String, 1 characters ) 3
page_num (Integer) 1
2 (Array, 11 elements)
nid (Integer) 24
cid (String, 1 characters ) 2
pid (String, 1 characters ) 0
form_key (String, 12 characters ) korpergrosse
name (String, 14 characters ) Körpergröße
type (String, 6 characters ) number
value (String, 0 characters )
extra (Array, 20 elements)
title_display (String, 6 characters ) inline
private (Integer) 0
wrapper_classes (String, 0 characters )
css_classes (String, 0 characters )
type (String, 6 characters ) select
min (String, 3 characters ) 100
max (String, 3 characters ) 140
step (String, 1 characters ) 5
field_prefix (String, 0 characters )
field_suffix (String, 0 characters )
disabled (Integer) 0
unique (Integer) 0
description (String, 0 characters )
attributes (Array, 0 elements)
analysis (Boolean) FALSE
decimals (String, 0 characters )
point (String, 1 characters ) .
separator (String, 1 characters ) ,
integer (Integer) 0
excludezero (Integer) 0
required (String, 1 characters ) 1
weight (String, 1 characters ) 4
page_num (Integer) 1
4 (Array, 11 elements)
nid (Integer) 24
cid (String, 1 characters ) 4
pid (String, 1 characters ) 0
form_key (String, 9 characters ) haarfarbe
name (String, 9 characters ) Haarfarbe
type (String, 6 characters ) select
value (String, 0 characters )
extra (Array, 15 elements)
items (String, 54 characters ) blonde|blond braune|braun schwarze|schwarz r...
blonde|blond braune|braun schwarze|schwarz rote|rot
multiple (Integer) 0
title_display (String, 6 characters ) inline
private (Integer) 0
wrapper_classes (String, 0 characters )
css_classes (String, 0 characters )
aslist (Integer) 1
empty_option (String, 0 characters )
optrand (Integer) 0
other_option (NULL)
other_text (String, 8 characters ) Other...
description (String, 0 characters )
custom_keys (Boolean) FALSE
options_source (String, 0 characters )
analysis (Boolean) TRUE
required (String, 1 characters ) 1
weight (String, 1 characters ) 5
page_num (Integer) 1
5 (Array, 11 elements)
nid (Integer) 24
cid (String, 1 characters ) 5
pid (String, 1 characters ) 0
form_key (String, 26 characters ) eine_farbe_der_schultasche
name (String, 26 characters ) Eine Farbe der Schultasche
type (String, 6 characters ) select
value (String, 0 characters )
extra (Array, 15 elements)
items (String, 79 characters ) rote| rot blaue| blau pinkfarbene|pink grün...
rote| rot blaue| blau pinkfarbene|pink grüne|grün rosa|rosa weiße|weiß
multiple (Integer) 0
title_display (String, 6 characters ) inline
private (Integer) 0
wrapper_classes (String, 0 characters )
css_classes (String, 0 characters )
aslist (Integer) 1
empty_option (String, 0 characters )
optrand (Integer) 0
other_option (NULL)
other_text (String, 8 characters ) Other...
description (String, 0 characters )
custom_keys (Boolean) FALSE
options_source (String, 0 characters )
analysis (Boolean) TRUE
required (String, 1 characters ) 1
weight (String, 1 characters ) 6
page_num (Integer) 1
6 (Array, 11 elements)
nid (Integer) 24
cid (String, 1 characters ) 6
pid (String, 1 characters ) 0
form_key (String, 28 characters ) zweite_farbe_der_schultasche
name (String, 28 characters ) Zweite Farbe der Schultasche
type (String, 6 characters ) select
value (String, 0 characters )
extra (Array, 15 elements)
items (String, 79 characters ) rote| rot blaue| blau pinkfarbene|pink grün...
rote| rot blaue| blau pinkfarbene|pink grüne|grün rosa|rosa weiße|weiß
multiple (Integer) 0
title_display (String, 6 characters ) inline
private (Integer) 0
wrapper_classes (String, 0 characters )
css_classes (String, 0 characters )
aslist (Integer) 1
empty_option (String, 0 characters )
optrand (Integer) 0
other_option (NULL)
other_text (String, 8 characters ) Other...
description (String, 0 characters )
custom_keys (Boolean) FALSE
options_source (String, 0 characters )
analysis (Boolean) TRUE
required (String, 1 characters ) 1
weight (String, 1 characters ) 7
page_num (Integer) 1
conditionals (Array, 0 elements)
cid (String, 1 characters ) 0
last_comment_timestamp (String, 10 characters ) 1435467630
last_comment_name (NULL)
last_comment_uid (String, 1 characters ) 1
comment_count (String, 1 characters ) 0
name (String, 5 characters ) Carla
picture (String, 1 characters ) 0
data (String, 4 characters ) b:0;
Krumo version 0.2.1a
| http://krumo.sourceforge.net
Wie muß ich da ['#default_value'] einbauen, damit der Cookie im Feld"Name des Kindes" erscheint?
Vielen Dank für Eure Mühe
Carla