Skip to content

Commit 2c0b02c

Browse files
authored
Add optional phone field to contact form, make fields optional required (#639)
1 parent e4d8df0 commit 2c0b02c

10 files changed

+351
-75
lines changed

assets/js/frontend.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ const observer = new IntersectionObserver(
1414
}
1515
);
1616

17-
observer.observe( stickyDetector );
17+
if ( stickyDetector ) {
18+
observer.observe( stickyDetector );
19+
}
1820

1921
jQuery( function () {
2022
jQuery( '.show-leaflet' ).on( 'click', function () {
@@ -131,6 +133,7 @@ jQuery( '#sunflower-contact-form' ).on( 'submit', function ( e ) {
131133
message: jQuery( '#message' ).val(),
132134
name: jQuery( '#name' ).val(),
133135
mail: jQuery( '#mail' ).val(),
136+
phone: jQuery( '#phone' ).val(),
134137
title: jQuery( '#contact-form-title' ).html(),
135138
captcha: jQuery( '#captcha' ).val(),
136139
},

functions/contact-form.php

+22-8
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,39 @@ function sunflower_contact_form() {
3030
die();
3131
}
3232

33-
$message = sanitize_textarea_field( $_POST['message'] );
34-
$name = sanitize_text_field( $_POST['name'] );
35-
$mail = sanitize_email( $_POST['mail'] );
36-
$title = sanitize_text_field( $_POST['title'] );
33+
$name = sanitize_text_field( $_POST['name'] );
34+
if ( $name ) {
35+
$message[] = sprintf( __( 'Name', 'sunflower-contact-form' ) . ': %s', $name );
36+
}
37+
38+
$mail = sanitize_email( $_POST['mail'] );
39+
if ( $mail ) {
40+
$message[] = sprintf( __( 'E-Mail', 'sunflower-contact-form' ) . ': %s', $mail );
41+
}
42+
43+
$phone = sanitize_text_field( $_POST['phone'] );
44+
if ( $phone ) {
45+
$message[] = sprintf( __( 'Phone', 'sunflower-contact-form' ) . ': %s', $phone );
46+
}
47+
48+
$message[] = "\n" . __( 'Message', 'sunflower-contact-form' ) . ': ' . sanitize_textarea_field( $_POST['message'] );
49+
50+
$title = sanitize_text_field( $_POST['title'] );
3751

3852
$response = __( 'Thank you. The form has been sent.', 'sunflower-contact-form' );
3953
$to = sunflower_get_setting( 'sunflower_contact_form_to' ) ? sunflower_get_setting( 'sunflower_contact_form_to' ) : get_option( 'admin_email' );
4054

41-
$subject = __( 'New Message from', 'sunflower-contact-form' ) . ' ' . ( $title ? $title : __( 'Contact Form', 'sunflower-contact-form' ) );
42-
$message = sprintf( "Name: %s\nE-Mail: %s\n\n%s", $name, $mail, $message );
55+
$subject = __( 'New Message from', 'sunflower-contact-form' ) . ' ' . ( $title ? $title : __( 'Contact Form', 'sunflower-contact-form' ) );
56+
$message_str = sprintf( '%s', implode( "\n", $message ) );
4357

4458
if ( ! empty( $mail ) ) {
4559
$headers = 'Reply-To: ' . $mail;
4660
}
4761

4862
if ( '' === $headers || '0' === $headers ) {
49-
wp_mail( $to, $subject, $message );
63+
wp_mail( $to, $subject, $message_str );
5064
} else {
51-
wp_mail( $to, $subject, $message, $headers );
65+
wp_mail( $to, $subject, $message_str, $headers );
5266
}
5367

5468
echo wp_json_encode(
270 Bytes
Binary file not shown.

languages/sunflower-contact-form-de_DE.po

+99-14
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ msgstr ""
55
"Project-Id-Version: sunflower 2.0.9\n"
66
"Report-Msgid-Bugs-To: https://wordpress.org/support/theme/sunflower-contact-"
77
"form\n"
8-
"POT-Creation-Date: 2024-04-16T11:04:23+00:00\n"
9-
"PO-Revision-Date: 2024-04-16 13:05+0200\n"
8+
"POT-Creation-Date: 2024-06-19T09:08:48+00:00\n"
9+
"PO-Revision-Date: 2024-06-19 11:09+0200\n"
1010
"Last-Translator: \n"
1111
"Language-Team: \n"
1212
"Language: de_DE\n"
@@ -18,36 +18,45 @@ msgstr ""
1818
"X-Domain: sunflower-contact-form\n"
1919

2020
#. Theme Name of the theme
21+
#: style.css
2122
msgid "sunflower"
2223
msgstr ""
2324

2425
#. Theme URI of the theme
26+
#: style.css
2527
msgid "https://sunflower-theme.de"
2628
msgstr ""
2729

2830
#. Description of the theme
31+
#: style.css
2932
msgid "Theme for the German Green Party"
3033
msgstr ""
3134

3235
#. Author of the theme
36+
#: style.css
3337
msgid "verdigado eG"
3438
msgstr ""
3539

3640
#. Author URI of the theme
41+
#: style.css
3742
msgid "https://verdigado.com"
3843
msgstr ""
3944

40-
#: build/contact-form/render.php:5 functions/contact-form.php:28
41-
#: build/contact-form/index.js:93 build/contact-form/index.js:80
45+
#: build/contact-form/render.php:11 functions/contact-form.php:55
46+
#: build/contact-form/index.js:104 build/contact-form/index.js:92
4247
msgid "Contact Form"
4348
msgstr "Kontaktformular"
4449

45-
#: build/contact-form/render.php:19
50+
#: build/contact-form/render.php:27 functions/contact-form.php:48
51+
msgid "Message"
52+
msgstr "Nachricht"
53+
54+
#: build/contact-form/render.php:30
4655
msgid "Please fill in all required (<span class=\"required\">*</span>) fields."
4756
msgstr ""
4857
"Bitte füllen Sie alle Pflichtfelder (<span class=\"required\">*</span>) aus."
4958

50-
#: build/contact-form/render.php:20
59+
#: build/contact-form/render.php:34
5160
msgid ""
5261
"By using this form, you consent to the storage and processing of your data "
5362
"through our website.\n"
@@ -59,31 +68,35 @@ msgstr ""
5968
"\t\tWeiteres entnehmen Sie bitte unserer <a href=\"#\" "
6069
"id=\"privacy_policy_url\">Datenschutzerklärung</a>"
6170

62-
#: build/contact-form/render.php:25
71+
#: build/contact-form/render.php:45 functions/contact-form.php:35
6372
msgid "Name"
6473
msgstr "Name"
6574

66-
#: build/contact-form/render.php:30
75+
#: build/contact-form/render.php:52 functions/contact-form.php:40
6776
msgid "E-Mail"
6877
msgstr "E-Mail"
6978

70-
#: build/contact-form/render.php:34
79+
#: build/contact-form/render.php:64 functions/contact-form.php:45
80+
msgid "Phone"
81+
msgstr "Telefon"
82+
83+
#: build/contact-form/render.php:74
7184
msgid "How much is 1 + 1 ?"
7285
msgstr "Was ist 1 + 1 ?"
7386

74-
#: build/contact-form/render.php:40
87+
#: build/contact-form/render.php:80
7588
msgid "submit"
7689
msgstr "absenden"
7790

78-
#: functions/contact-form.php:25
91+
#: functions/contact-form.php:52
7992
msgid "Thank you. The form has been sent."
8093
msgstr "Vielen Dank. Ihre Nachricht wurde verschickt."
8194

82-
#: functions/contact-form.php:28
95+
#: functions/contact-form.php:55
8396
msgid "New Message from"
8497
msgstr "Neue Nachricht über"
8598

86-
#: build/contact-form/index.js:89 build/contact-form/index.js:67
99+
#: build/contact-form/index.js:100 build/contact-form/index.js:79
87100
msgid ""
88101
"The receiver address may be altered within the Sunflower theme settings. By "
89102
"default, emails are sent to the site administrator."
@@ -92,10 +105,22 @@ msgstr ""
92105
"werden. Standardmäßig wird das Formular an den*die Webseiten-"
93106
"Administrator*in gesendet."
94107

95-
#: build/contact-form/index.js:91 build/contact-form/index.js:75
108+
#: build/contact-form/index.js:102 build/contact-form/index.js:87
96109
msgid "Title of the form"
97110
msgstr "Titel des Formulars"
98111

112+
#: build/contact-form/index.js:107 build/contact-form/index.js:99
113+
msgid "Require E-Mail"
114+
msgstr "E-Mail ist Pflichtfeld"
115+
116+
#: build/contact-form/index.js:111 build/contact-form/index.js:104
117+
msgid "Display Phone Field"
118+
msgstr "Telefon-Feld anzeigen"
119+
120+
#: build/contact-form/index.js:115 build/contact-form/index.js:109
121+
msgid "Require Phone"
122+
msgstr "Telefon ist Pflichtfeld"
123+
99124
#: build/contact-form/block.json
100125
msgctxt "block title"
101126
msgid "Contact Form (Sunflower)"
@@ -105,3 +130,63 @@ msgstr "Kontaktformular ( Sunflower)"
105130
msgctxt "block description"
106131
msgid "Simple Contact Form"
107132
msgstr "Einfaches Kontaktformular"
133+
134+
#: theme.json
135+
msgctxt "Color name"
136+
msgid "Himmel"
137+
msgstr ""
138+
139+
#: theme.json
140+
msgctxt "Color name"
141+
msgid "Tanne"
142+
msgstr ""
143+
144+
#: theme.json
145+
msgctxt "Color name"
146+
msgid "Klee"
147+
msgstr ""
148+
149+
#: theme.json
150+
msgctxt "Color name"
151+
msgid "Klee-700"
152+
msgstr ""
153+
154+
#: theme.json
155+
msgctxt "Color name"
156+
msgid "Grashalm"
157+
msgstr ""
158+
159+
#: theme.json
160+
msgctxt "Color name"
161+
msgid "White"
162+
msgstr ""
163+
164+
#: theme.json
165+
msgctxt "Color name"
166+
msgid "Sonne"
167+
msgstr ""
168+
169+
#: theme.json
170+
msgctxt "Color name"
171+
msgid "Sand"
172+
msgstr ""
173+
174+
#: theme.json
175+
msgctxt "Color name"
176+
msgid "Gray"
177+
msgstr ""
178+
179+
#: theme.json
180+
msgctxt "Color name"
181+
msgid "Black"
182+
msgstr ""
183+
184+
#: theme.json
185+
msgctxt "Font family name"
186+
msgid "PT Sans"
187+
msgstr ""
188+
189+
#: theme.json
190+
msgctxt "Font family name"
191+
msgid "GrueneType"
192+
msgstr ""

0 commit comments

Comments
 (0)