• I have a WPForm created for a number of fields. Normally each field is stored in the postmeta table. However, if the value of the WPForm field is blank, no data is stored in the postmeta table.

    How can I get WPForms to store a value (eg create the row entry) for a field that’s blank?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Ethan Choi

    (@ethanchoi)

    Hi @ricks03,

    I apologize as customizations like this is outside of our scope for support. In case it helps, you can check out our developers’ documentation as a reference.

    Thanks!

    Thread Starter ricks03

    (@ricks03)

    I didn’t expect it to be a customization, I expected it to be a flag or default value or something?

    Thread Starter ricks03

    (@ricks03)

    Or WPForms support could provide me the answer – which they did.

    “I have checked this with the development team and they have sent me a code snippet to achieve what you have requested:

    add_filter( 'wpforms_entry_save_data', static
    function ( $fields, $entry, $form_data ) {
    
    	$value1 = '';
    	$value2 = '';
    
    	// These are field IDs to take data from, and to merge into.
    	$field1_id = 1;
    	$field2_id = 2;
    	$merged_id = 3;
    
    	foreach ( $fields as $field ) {
    		if ( $field['id'] === $field1_id ) {
    			$value1 = $field['value'];
    		}
    		if ( $field['id'] === $field2_id ) {
    			$value2 = $field['value'];
    		}
    	}
    
    	$fields[ $merged_id ]['value'] = $value1 . ' - ' . $value2;
    
    	return $fields;
    }, 10, 3 );

    Simply create 2 Single Line Text fields and a Hidden field,
    which will store the merged text fields when the form is submitted.
    Please doublecheck if you have used the correct IDs for the Text and
    hidden fields. $merged_id is where data will be saved (hidden field).
    In case it helps, here’s our tutorial with the most common ways to add
    custom code like this:
    https://wpforms.com/developers/how-to-add-custom-php-or-javascript-for-wpforms/.
    For the most beginner-friendly option in that tutorial, I’d recommend
    using the Code Snippets plugin:
    http://www.wpbeginner.com/plugins/how-to-easily-add-custom-code-in-wordpress-without-breaking-your-site/.
    This will protect your code from updates and keep it easy to manage
    right within your WordPress admin area.I hope this helps!

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

The topic ‘Submitting a blank field in WPForms’ is closed to new replies.