• Resolved alwanma27

    (@alwanma27)


    Hello,

    Hope this message finds you well.

    I have a form where I have a select field and an upload file field. I want to ask about why when the form is submitted the label of the option selected is saved in the DB instead of the value? What can I do to save value of the selected option instead of the label? How can I obtain only the URL of the uploaded file?

    Thank you
    Regards

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @alwanma27

    I hope you are doing well.

    It is expected, that you can modify this behaviour in the Form > Settings: https://monosnap.com/file/X3FQl2VY4Nu8GzqeoCU5KCJKBo8T2U

    How can I obtain only the URL of the uploaded file?

    Are you looking to get it by email or at any specific location?

    By default, it goes to email when using the {all_fields} https://monosnap.com/file/Lvhdsqek5FGNOcPpYgomUwcoOT7Nd5

    Best Regards
    Patrick Freitas

    Thread Starter alwanma27

    (@alwanma27)

    Hello Patrick,

    Thank you for your response.

    Deal for the select value. Now for the upload link i want to get it on form submition to be send it using an api to another location. In other word, I should use it in a code that i have add it in the mu-plugin folder where i have to get the select value and the upload link to send it to my company using API that i have made.

    Thank you
    Regards

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @alwanma27

    I don’t know how your API works but this would require custom code anyway. You can use this as a starting point (and modify it to your needs) then:

    https://gist.github.com/adczk/a314ad50036ffd449147d28f2e876e2b

    Best regards,
    Adam

    Thread Starter alwanma27

    (@alwanma27)

    Hello Adam,

    Thank you for your response.

    I will try it but what i mean how can i get the upload file url only from the database.

    Thank you
    Regards

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    HI @alwanma27

    The code that I shared takes all the data of current submission so you can use them whatever way you want. If we “strip” everything else form that code, the example code could be

    add_filter( 'forminator_custom_form_submit_field_data', 'forminator_external_url_post', 10, 2);
    function forminator_external_url_post( $field_data, $id ) {
    	
    	//error_log( print_r( $field_data, true ) ); 
    	
    	$upload_url = '';
    	$upload_path = '';
    	
    	foreach ( $field_data as $field ) {
    		
    		if ( $field['name'] === 'upload-1' ) {
    			
    			$upload_url = $field['value']['file']['file_url'];
    			$upload_path = $field['value']['file']['file_path'];
    		}
    		
    	}
    	
    	
    	return $field_data;
    	
    }

    Assuming that your upload field ID is {upload-1} and it’s a single upload field, you’ll get the file URL in $upload_url and file path in $upload_path variable upon form submission. This will be run when the form is submitted. You can uncomment the error_log line to see structure of the $field_data table in the debug.log file (if you enable debugging in WordPress).

    If you want to read the data form the database instead then you would need to use Forminator API and this particular method

    https://wpmudev.com/docs/api-plugin-development/forminator-api-docs/#method-get_entry

    Kind regards,
    Adam

    Thread Starter alwanma27

    (@alwanma27)

    Hello Adam,

    Thank you for your help.

    Regards,

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Select Field value issue and uploaded file URL’ is closed to new replies.