@@ -136,13 +136,28 @@ private function get_hidden_fields() {
136
136
}
137
137
138
138
/**
139
- * Get value by tag.
139
+ * Get values by tag.
140
140
*
141
141
* @param WPCF7_FormTag $tag Tag.
142
- * @return string
142
+ * @return array< string>
143
143
*/
144
- public function get_value_by_tag ( $ tag ) {
145
- $ value = $ this ->submission ->get_posted_string ( $ tag ->name );
144
+ public function get_values_by_tag ( $ tag ) {
145
+ /**
146
+ * Hidden fields.
147
+ */
148
+ $ hidden_fields = $ this ->get_hidden_fields ();
149
+
150
+ if ( \in_array ( $ tag ->name , $ hidden_fields , true ) ) {
151
+ return [];
152
+ }
153
+
154
+ $ data = $ this ->submission ->get_posted_data ( $ tag ->name );
155
+
156
+ if ( null === $ data ) {
157
+ return [];
158
+ }
159
+
160
+ $ data = \wpcf7_array_flatten ( $ data );
146
161
147
162
/**
148
163
* Contact Form 7 concatenates the field option value with user input for free text fields. We
@@ -151,25 +166,32 @@ public function get_value_by_tag( $tag ) {
151
166
* @link https://github.com/rocklobster-in/contact-form-7/blob/2cfaa472fa485c6d3366fcdd80701fdaf7f9e425/includes/submission.php#L434-L437
152
167
*/
153
168
if ( \wpcf7_form_tag_supports ( $ tag ->type , 'selectable-values ' ) && $ tag ->has_option ( 'free_text ' ) ) {
154
- $ values = \WPCF7_USE_PIPE ? $ tag ->pipes ->collect_afters () : $ tag ->values ;
169
+ $ tag_values = \WPCF7_USE_PIPE ? $ tag ->pipes ->collect_afters () : $ tag ->values ;
155
170
156
- $ last_value = \end ( $ values );
171
+ $ tag_value_last = \end ( $ tag_values );
157
172
158
- if ( \str_starts_with ( $ value , $ last_value . ' ' ) ) {
159
- $ value = \substr ( $ value , \strlen ( $ last_value . ' ' ) );
173
+ $ value = \array_pop ( $ data );
174
+
175
+ if ( \str_starts_with ( $ value , $ tag_value_last . ' ' ) ) {
176
+ $ value = \substr ( $ value , \strlen ( $ tag_value_last . ' ' ) );
160
177
}
178
+
179
+ $ data [] = $ value ;
161
180
}
162
181
163
- /**
164
- * Hidden fields.
165
- */
166
- $ hidden_fields = $ this ->get_hidden_fields ();
182
+ return $ data ;
183
+ }
167
184
168
- if ( \in_array ( $ tag ->name , $ hidden_fields , true ) ) {
169
- $ value = '' ;
170
- }
185
+ /**
186
+ * Get value by tag.
187
+ *
188
+ * @param WPCF7_FormTag $tag Tag.
189
+ * @return string
190
+ */
191
+ public function get_value_by_tag ( $ tag ) {
192
+ $ values = $ this ->get_values_by_tag ( $ tag );
171
193
172
- return $ value ;
194
+ return \implode ( ' , ' , $ values ) ;
173
195
}
174
196
175
197
/**
0 commit comments