Update selected value on form submission (ACF)
-
Hi all,
I’ve created a front-end WordPress user settings form and added some custom fields to it using the Advanced Custom Fields plugin. The code for this page checks if there were no issues on form submission and then redirects the user to the same page with updated field values.
I’m successfully able to fetch the values of all custom fields, as well as update the values of all custom fields, except one. It’s a <select> element. I want the selected value to be updated in the backend upon form submission but it just won’t work. Here is the code that I’m using to do this:
if ( !empty( $_POST['field_53207aa87753e'] ) ) { $set_state = $_POST['field_53207aa87753e']; // Stores the selected <select> option value update_field($state_fkey, $set_state, 'user_'.$current_user->ID);
Here is the output of the “$state” variable that’s storing values for the <select> element:
Array ( [key] => field_53207aa87753e [label] => State [name] => state [_name] => state [type] => select [order_no] => 3 [instructions] => [required] => 1 [id] => acf-field-state [class] => select [conditional_logic] => Array ( [status] => 0 [rules] => Array ( [0] => Array ( [field] => null [operator] => == [value] => ) ) [allorany] => all ) [choices] => Array ( [AL] => Alabama [AK] => Alaska [AZ] => Arizona [AR] => Arkansas [CA] => California [CO] => Colorado [CT] => Connecticut [DE] => Delaware [DC] => District Of Columbia [FL] => Florida [GA] => Georgia [HI] => Hawaii [ID] => Idaho [IL] => Illinois [IN] => Indiana [IA] => Iowa [KS] => Kansas [KY] => Kentucky [LA] => Louisiana [ME] => Maine [MD] => Maryland [MA] => Massachusetts [MI] => Michigan [MN] => Minnesota [MS] => Mississippi [MO] => Missouri [MT] => Montana [NE] => Nebraska [NV] => Nevada [NH] => New Hampshire [NJ] => New Jersey [NM] => New Mexico [NY] => New York [NC] => North Carolina [ND] => North Dakota [OH] => Ohio [OK] => Oklahoma [OR] => Oregon [PA] => Pennsylvania [RI] => Rhode Island [SC] => South Carolina [SD] => South Dakota [TN] => Tennessee [TX] => Texas [UT] => Utah [VT] => Vermont [VA] => Virginia [WA] => Washington [WV] => West Virginia [WI] => Wisconsin [WY] => Wyoming ) [default_value] => AL: Alabama [allow_null] => 0 [multiple] => 0 [field_group] => 900 [value] => AR )
I’ve been searching the web and the ACF forum/documentation for the past 2 days but can’t find a solution for this. I can properly echo the value of $set_state but when I’m trying to update it, it just won’t update.
Please help!
Thanks!
- The topic ‘Update selected value on form submission (ACF)’ is closed to new replies.