Title: Custom Selectbox Data
Last modified: August 1, 2022

---

# Custom Selectbox Data

 *  Resolved [satrya](https://wordpress.org/support/users/satrya/)
 * (@satrya)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/custom-selectbox-data/)
 * Hi there,
    So, I need a custom select box data, the data is ok, but I can’t submit
   the form. Please [see this image ](https://monosnap.com/file/rTLlI8C9bX9fcsw2473wMXBTX1izYL).
   Here’s my code [https://gist.github.com/gasatrya/57e26a7cded08c6af10fc0f0feddfe18](https://gist.github.com/gasatrya/57e26a7cded08c6af10fc0f0feddfe18)
 * Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Support [Laura – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support8/)
 * (@wpmudev-support8)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/custom-selectbox-data/#post-15877149)
 * Hi [@satrya](https://wordpress.org/support/users/satrya/)
 * I hope you’re well today!
 * I briefly checked the code and it looks fine at first glance. It did work with
   an “ad hoc” created form on my end too but I think this test wasn’t quite reliable
   as I only used very basic form and basic ACF fields. It would be much better 
   if I could reproduce your setup as close as possible.
 * That being said, would you be able to also provide export of the form itself (
   the form that you’re experiencing issues with)?
 * To share export of the form, simply put export file (of a form, not its submissions!)
   on your Google Drive, Dropbox or similar account and share direct link to it 
   in your response here (note: you may want to remove e-mail notifications first
   so not to sure e-mails publicly).
 * It would be even better if you could provide (the same way) export of relevant
   ACF fields/groups as this way we could set similar configuration on test site
   and check what is happening and how to fix that.
 * Kind regards,
    Adam
 *  Thread Starter [satrya](https://wordpress.org/support/users/satrya/)
 * (@satrya)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/custom-selectbox-data/#post-15879837)
 * Hi Adam,
    Thank you, but I am using ACF pro, because it is a repeater field. 
   I hope you also have the pro version. So, here’s the file.
 * [ACF json file](https://send.bitwarden.com/#5gGIZC2xYkOsQq7lAGxi7A/PlJ6P1tU43YV1WZ7aJdv3A)
 * Forminator export:
    `{"type":"form","data":{"fields":[{"id":"text-1","element_id":"
   text-1","form_id":"wrapper-3753-7750","type":"text","options":[],"cols":"12","
   conditions":[],"wrapper_id":"wrapper-3753-7750","input_type":"line","limit_type":"
   characters","field_label":"Text","placeholder":"E.g. text placeholder"},{"id":"
   select-1","element_id":"select-1","form_id":"wrapper-1252-4582","type":"select","
   options":[],"cols":"12","conditions":[],"wrapper_id":"wrapper-1252-4582","value_type":"
   multiselect","field_label":"Select","options_bulk_editor":"","options_expanded":""}],"
   settings":{"pagination-header":"nav","paginationData":{"pagination-header-design":"
   show","pagination-header":"nav"},"formName":"Testing Form","version":"1.17.2","
   form-border-style":"none","form-padding":"","form-border":"","fields-style":"
   open","validation":"on_submit","akismet-protection":"0","form-style":"flat","
   enable-ajax":"true","autoclose":"true","submission-indicator":"show","indicator-
   label":"Submitting...","form-type":"default","submission-behaviour":"behaviour-
   thankyou","thankyou-message":"Thank you for contacting us, we will be in touch
   shortly.","submitData":{"custom-submit-text":"Send Message","custom-invalid-form-
   message":"Error: Your form is not valid, please fix the errors!"},"validation-
   inline":"1","form-expire":"no_expire","form-padding-top":"0","form-padding-right":"
   0","form-padding-bottom":"0","form-padding-left":"0","form-border-width":"0","
   form-border-radius":"0","cform-label-font-family":"Roboto","cform-label-custom-
   family":"","cform-label-font-size":"12","cform-label-font-weight":"bold","cform-
   title-font-family":"Roboto","cform-title-custom-family":"","cform-title-font-
   size":"45","cform-title-font-weight":"normal","cform-title-text-align":"left","
   cform-subtitle-font-family":"Roboto","cform-subtitle-custom-font":"","cform-subtitle-
   font-size":"18","cform-subtitle-font-weight":"normal","cform-subtitle-text-align":"
   left","cform-input-font-family":"Roboto","cform-input-custom-font":"","cform-
   input-font-size":"16","cform-input-font-weight":"normal","cform-radio-font-family":"
   Roboto","cform-radio-custom-font":"","cform-radio-font-size":"14","cform-radio-
   font-weight":"normal","cform-select-font-family":"Roboto","cform-select-custom-
   family":"","cform-select-font-size":"16","cform-select-font-weight":"normal","
   cform-multiselect-font-family":"Roboto","cform-multiselect-custom-font":"","cform-
   multiselect-font-size":"16","cform-multiselect-font-weight":"normal","cform-dropdown-
   font-family":"Roboto","cform-dropdown-custom-font":"","cform-dropdown-font-size":"
   16","cform-dropdown-font-weight":"normal","cform-calendar-font-family":"Roboto","
   cform-calendar-custom-font":"","cform-calendar-font-size":"13","cform-calendar-
   font-weight":"normal","cform-button-font-family":"Roboto","cform-button-custom-
   font":"","cform-button-font-size":"14","cform-button-font-weight":"500","cform-
   timeline-font-family":"Roboto","cform-timeline-custom-font":"","cform-timeline-
   font-size":"12","cform-timeline-font-weight":"normal","cform-pagination-font-
   family":"","cform-pagination-custom-font":"","cform-pagination-font-size":"16","
   cform-pagination-font-weight":"normal","payment_require_ssl":"","submission-file":"
   delete","store_submissions":"1","form_name":"testing-form","form_status":"publish","
   sc_email_link":"1","sc_message":"<p>Your form has been saved as draft and a resume
   link has been generated so you can return to the form anytime within {retention_period}
   days from today. Copy and save the link or enter your email address below to 
   have the link sent to your mail.</p><p>These fields weren't saved to your submission
   draft: Paypal, Stripe, Signature, Password, Captcha, and Upload. Kindly fill 
   them out before submitting the form.</p>"},"client_id":null,"integration_conditions":[],"
   behaviors":[{"slug":"behavior-1234-4567","label":"","autoclose-time":"5","autoclose":"
   true","newtab":"sametab","thankyou-message":"Thank you for contacting us, we 
   will be in touch shortly.","email-thankyou-message":"","manual-thankyou-message":"","
   submission-behaviour":"behaviour-thankyou","redirect-url":""}],"notifications":[{"
   slug":"notification-1234-4567","label":"Admin Email","email-recipients":"default","
   recipients":"satrya@idenovasi.com","email-subject":"New Form Entry #{submission_id}
   for {form_name}","email-editor":"You have a new website form submission: <br /
   > {all_fields} <br />---<br /> This message was sent from {site_url}.","email-
   attachment":"true","type":"default"}]},"status":"publish","version":"1.17.2"}`
 * PHP function:
    [https://gist.github.com/gasatrya/378b27cd31a04313d213d95628aa02ca](https://gist.github.com/gasatrya/378b27cd31a04313d213d95628aa02ca)
 * —
 * 1. Please install ACF Pro and import the fields.
    2. Import the form. 3. Create
   a new page, then add the imported form. 4. Access the page `http://localhost/
   page-name/?attr_id=POST_ID` (please change the POST ID)
    -  This reply was modified 3 years, 10 months ago by [satrya](https://wordpress.org/support/users/satrya/).
    -  This reply was modified 3 years, 10 months ago by [satrya](https://wordpress.org/support/users/satrya/).
 *  Thread Starter [satrya](https://wordpress.org/support/users/satrya/)
 * (@satrya)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/custom-selectbox-data/#post-15886682)
 * Hi Adam,
    Any update on this?
 * What I want to achieve is, to display custom data, from a custom field to a multi
   select field. Now, if I do that by following [this script](https://gist.github.com/patrickfreitasdev/d7ad926561db4b598baeaf66478d790b),
   I couldn’t submit the form, it said the form is error.
 *  Plugin Support [Nithin – WPMU DEV Support](https://wordpress.org/support/users/wpmudevsupport11/)
 * (@wpmudevsupport11)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/custom-selectbox-data/#post-15888025)
 * Hi [@satrya](https://wordpress.org/support/users/satrya/),
 * I have tweaked the script which you have mentioned in here:
    [https://gist.github.com/patrickfreitasdev/d7ad926561db4b598baeaf66478d790b](https://gist.github.com/patrickfreitasdev/d7ad926561db4b598baeaf66478d790b)
 * Could you please try the following code instead of the above and see how it goes:
 *     ```
       <?php
   
       add_filter(
       	'forminator_cform_render_fields',
       	function( $wrappers, $model_id ) {
       		if( $model_id != 1147 ){
       			return $wrappers;
       		}
   
       		$select_fields_data = array(
       			'select-1' => 'post',
       		);
   
       		foreach ( $wrappers as $wrapper_key => $wrapper ) {
       			if ( ! isset( $wrapper[ 'fields' ] ) ) {
       				continue;
       			}
   
       			if ( 
       				isset( $select_fields_data[ $wrapper[ 'fields' ][ 0 ][ 'element_id' ] ] ) &&
       				! empty( $select_fields_data[ $wrapper[ 'fields' ][ 0 ][ 'element_id' ] ] )
       			) {
       				$posts = get_posts( array( 'post_type' => $select_fields_data[ $wrapper[ 'fields' ][ 0 ][ 'element_id' ] ] ) );
   
       				if ( ! empty( $posts ) ) {
       					$new_options = array();
       					$opt_data = array();
       					foreach( $posts as $post ) {
       						$new_options[] = array(
       							'label' => $post->post_title,
       							'value' => $post->post_title,
       							'limit' => '',
       							'key'   => forminator_unique_key(),
       						);
       						$opt_data['options'] = $new_options;
       					}
       					$select_field = Forminator_API::get_form_field( $model_id, $wrapper['fields'][0]['element_id'], true );
       					if( $select_field ){
       						if( $select_field['options'][0]['label'] != $opt_data['options'][0]['label'] ){
       							Forminator_API::update_form_field( $model_id, $wrapper['fields'][0]['element_id'], $opt_data );
       							$wrappers[ $wrapper_key ][ 'fields' ][ 0 ][ 'options' ] = $new_options;
       						}
       					}
       				}
       			}
       		}
   
       		return $wrappers;
       	},
       	10,
       	2
       );
   
       add_filter(
       	'forminator_replace_form_data', 
       	function( $content, $data, $fields ) {
       		if( $data['form_id'] != 1147 ){
       			return $content;
       		}
   
       		if ( ! empty( $content ) ) {
       			return $content;
       		}
   
       		$form_fields = Forminator_API::get_form_fields( $data['form_id'] );
       		$data_field = '';
       		foreach($data as $key => $value){
       	    	if ( strpos( $key, 'select' ) !== false ) {
       	    		$values = '';
       	    		$field_value = isset( $data[ $key ] ) ? $data[ $key ] : null;
   
       		    	if ( ! is_null( $field_value ) ) {
       		    		$fields_slugs  = wp_list_pluck( $form_fields, 'slug' );
       					$field_key     = array_search( $key, $fields_slugs, true );
       					$field_options = false !== $field_key && ! empty( $form_fields[ $field_key ]->raw['options'] )
       							? wp_list_pluck( $form_fields[ $field_key ]->options, 'label', 'value' )
       							: array();
   
       					if ( ! isset( $field_options[ $field_value ] ) && isset( $_POST[ $key ] ) ) {
       						return sanitize_text_field( $_POST[ $key ] );
       					}
       				}
       			}
       		}
       	    return $content;
       	},
       	10,
       	3
       );
       ```
   
 * You’ll have to make sure to update the following lines in the above code:
 *     ```
       if( $model_id != 1147 ){
       if( $data['form_id'] != 1147 ){
       ```
   
 * To your form ID, suppose the form ID is 123, then the above line will be changed
   to:
 *     ```
       if( $model_id != 123 ){
       if( $data['form_id'] != 123 ){
       ```
   
 * Please do let us know how that goes.
 * Kind Regards,
    Nithin
 *  Thread Starter [satrya](https://wordpress.org/support/users/satrya/)
 * (@satrya)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/custom-selectbox-data/#post-15895889)
 * Thanks Nithin, it is working!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Custom Selectbox Data’ is closed to new replies.

 * ![](https://ps.w.org/forminator/assets/icon-256x256.gif?rev=3443182)
 * [Forminator Forms – Contact Form, Payment Form & Custom Form Builder](https://wordpress.org/plugins/forminator/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/forminator/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/forminator/)
 * [Active Topics](https://wordpress.org/support/plugin/forminator/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/forminator/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/forminator/reviews/)

 * 5 replies
 * 3 participants
 * Last reply from: [satrya](https://wordpress.org/support/users/satrya/)
 * Last activity: [3 years, 9 months ago](https://wordpress.org/support/topic/custom-selectbox-data/#post-15895889)
 * Status: resolved