{"id":15596786,"date":"2022-04-27T15:29:30","date_gmt":"2022-04-27T15:29:30","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/php-fatal-error-uncaught-typeerror-trim\/"},"modified":"2022-04-27T15:29:30","modified_gmt":"2022-04-27T15:29:30","slug":"php-fatal-error-uncaught-typeerror-trim","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/php-fatal-error-uncaught-typeerror-trim\/","title":{"rendered":"PHP Fatal error: Uncaught TypeError: trim()"},"content":{"rendered":"<p>Using php8.1 along with the Constant Contact integration that comes with CF7.<\/p>\n<p>I am getting the below error when attempting to submit a form where I have a select in use so users can select their state instead of typing it in. I have copied\/pasted that input below. When the data is posted to the server, the your-address-state is posted as a string. When CF7 is processing the data to create the $submission-&gt;posted_data in at about \/includes\/submission.php:319 that string is converted into an array with <code>$value = (array) $value;<\/code>. Later on down the line the Constant Contact module calls the add_street_address function where the error occurs. <\/p>\n<p>In the interim, I will probably just allow users to type in their state or rollback to a previous version of php.<\/p>\n<p><code>[select* your-address-state include_blank &quot;Alabama&quot;&quot;Alaska&quot;&quot;Arizona&quot;&quot;Arkansas&quot;&quot;California&quot;&quot;Colorado&quot;&quot;Connecticut&quot;&quot;Delaware&quot;&quot;Florida&quot;&quot;Georgia&quot;&quot;Hawaii&quot;&quot;Idaho&quot;&quot;Illinois&quot;&quot;Indiana&quot;&quot;Iowa&quot;&quot;Kansas&quot;&quot;Kentucky&quot;&quot;Louisiana&quot;&quot;Maine&quot;&quot;Maryland&quot;&quot;Massachusetts&quot;&quot;Michigan&quot;&quot;Minnesota&quot;&quot;Mississippi&quot;&quot;Missouri&quot;&quot;Montana&quot;&quot;Nebraska&quot;&quot;Nevada&quot;&quot;New Hampshire&quot;&quot;New Jersey&quot;&quot;New Mexico&quot;&quot;New York&quot;&quot;North Carolina&quot;&quot;North Dakota&quot;&quot;Ohio&quot;&quot;Oklahoma&quot;&quot;Oregon&quot;&quot;Pennsylvania&quot;&quot;Rhode Island&quot;&quot;South Carolina&quot;&quot;South Dakota&quot;&quot;Tennessee&quot;&quot;Texas&quot;&quot;Utah&quot;&quot;Vermont&quot;&quot;Virginia&quot;&quot;Washington&quot;&quot;Washington D.C.&quot;&quot;West Virginia&quot;&quot;Wisconsin&quot;&quot;Wyoming&quot;]<\/code><\/p>\n<pre><code>[26-Apr-2022 21:56:52 UTC] PHP Fatal error:  Uncaught TypeError: trim(): Argument #1 ($string) must be of type string, array given in \/home\/site\/public_html\/wp-content\/plugins\/contact-form-7\/modules\/constant-contact\/contact-post-request.php:282\nStack trace:\n#0 \/home\/site\/public_html\/wp-content\/plugins\/contact-form-7\/modules\/constant-contact\/contact-post-request.php(282): trim(Array)\n#1 \/home\/site\/public_html\/wp-content\/plugins\/contact-form-7\/modules\/constant-contact\/contact-post-request.php(86): WPCF7_ConstantContact_ContactPostRequest-&gt;add_street_address(&#039;&#039;, &#039;&#039;, Array, &#039;&#039;, &#039;&#039;)\n#2 \/home\/site\/public_html\/wp-content\/plugins\/contact-form-7\/modules\/constant-contact\/constant-contact.php(95): WPCF7_ConstantContact_ContactPostRequest-&gt;build(Object(WPCF7_Submission))\n#3 \/home\/site\/public_html\/wp-includes\/class-wp-hook.php(303): wpcf7_constant_contact_submit(Object(WPCF7_ContactForm), Array)#4 \/home\/site\/public_html\/wp-includes\/class-wp-hook.php(327): WP_Hook-&gt;apply_filters(&#039;&#039;, Array)\n#5 \/home\/site\/public_html\/wp-includes\/plugin.php(470): WP_Hook-&gt;do_action(Array)#6 \/home\/site\/public_html\/wp-content\/plugins\/contact-form-7\/includes\/contact-form.php(1055): do_action(&#039;wpcf7_submit&#039;, Object(WPCF7_ContactForm), Array)\n#7 \/home\/site\/public_html\/wp-content\/plugins\/contact-form-7\/includes\/rest-api.php(336): WPCF7_ContactForm-&gt;submit()\n#8 \/home\/site\/public_html\/wp-includes\/rest-api\/class-wp-rest-server.php(1140): WPCF7_REST_Controller-&gt;create_feedback(Object(WP_REST_Request))\n#9 \/home\/site\/public_html\/wp-includes\/rest-api\/class-wp-rest-server.php(987): WP_REST_Server-&gt;respond_to_request(Object(WP_REST_Request), &#039;\/contact-form-7...&#039;,Array, NULL)\n#10 \/home\/site\/public_html\/wp-includes\/rest-api\/class-wp-rest-server.php(414): WP_REST_Server-&gt;dispatch(Object(WP_REST_Request))\n#11 \/home\/site\/public_html\/wp-includes\/rest-api.php(370): WP_REST_Server-&gt;serve_request(&#039;\/contact-form-7...&#039;)\n#12 \/home\/site\/public_html\/wp-includes\/class-wp-hook.php(303): rest_api_loaded(Object(WP))\n#13 \/home\/site\/public_html\/wp-includes\/class-wp-hook.php(327): WP_Hook-&gt;apply_filters(&#039;&#039;, Array)\n#14 \/home\/site\/public_html\/wp-includes\/plugin.php(518): WP_Hook-&gt;do_action(Array)\n#15 \/home\/site\/public_html\/wp-includes\/class-wp.php(388): do_action_ref_array(&#039;parse_request&#039;, Array)\n#16 \/home\/site\/public_html\/wp-includes\/class-wp.php(750): WP-&gt;parse_request(&#039;&#039;)\n#17 \/home\/site\/public_html\/wp-includes\/functions.php(1291): WP-&gt;main(&#039;&#039;)\n#18 \/home\/site\/public_html\/wp-blog-header.php(16): wp()\n#19 \/home\/site\/public_html\/index.php(17): require(&#039;\/home\/site...&#039;)\n#20 {main}\n  thrown in \/home\/site\/public_html\/wp-content\/plugins\/contact-form-7\/modules\/constant-contact\/contact-post-request.php on line 282<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-15596786","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/15596786","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/15596786\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=15596786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}