Skip Navigation

[Resolved] Empty Form Value

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 11 replies, has 2 voices.

Last updated by fahimS-2 1 year, 10 months ago.

Assisted by: Minesh.

Author
Posts
#2571933

I have a Post Edit form and it has one form field which collects user data for a custom field. Now in the frontend, the form field displays the custom field value in it. I don't want to show it. How can I remove it?

#2572035

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Do you mean that you want to show the field on edit form with blank/empty value and allow users to add another value or what if you remove the field directly from the form it user intervention is not required?

#2572037

Yes, I want to show the form field as empty and allow users to add another value.

#2572049

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

You can use the Toolset form hook "cred_filter_field_before_add_to_form" to change the form field value on fly.

You can add the following code to "Custom code" section offered by Toolset:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#adding-custom-php-code-using-toolset

add_filter('cred_filter_field_before_add_to_form', 'func_adjust_conflict_conditions', 10, 1);
function func_adjust_conflict_conditions($field){
   $form_id = 0;
   $form_html_id = $field['form_html_id'];
    
   if ( isset($form_html_id) ) {
        $parts = explode( '_', $form_html_id);
        $form_id = (int) $parts[2];
    }
     
    $field_slugs = array('book');
    if($form_id==99999 and in_array($field['id'],$field_slugs)){

       // in some cases $fields['data'] is an empty string, so you'll need to first set it's expected format for PHP 7.1 compatibility
        if (!is_array($field['data'])) {
            $field['data'] = array();
        }
      
      $field['field_value'] = '';
  
        
    }
    return $field;
}

Where:
- Replace $field_slugs with your original field slug.
- Replace 99999 with your original form ID.

More info:
- https://toolset.com/documentation/programmer-reference/cred-api/#cred_filter_field_before_add_to_form

#2572495

I changed the field slugs and form Id but the code isn't working for me. You can check here: hidden link

According to the documentation, $field array doesn't have any field_value element. Can you kindly check.

Waiting for your reply.

#2572501

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please share problem URL where you added your form as well as admin access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2572595

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok you are using the edit post form so I've disable the hook "cred_filter_field_before_add_to_form" you have added to "Custom Code" section.

I've added the following custom JS code to remove the rating field value to your form's JS box:
=> hidden link

jQuery(document).ready(function($){
$("input[name='wpcf-rating']").val('');
});

I can see now the rating field value is gone.

#2572699

Hi, thanks for your solution. Users can still see the value for a few seconds till the DOM is ready. isn't there any way from the backend?

#2572711

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Then you will have to compromise a bit and I've set the default value to 0.

=> hidden link

With that be ok?

#2572763

Yes, that will be fine. Do I still need to use the php code?

#2572767

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

No - I already disable that.

#2573421

My issue is resolved now. Thank you!