Skip Navigation

[Resolved] Cannot create required field

This support ticket is created 5 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 22 replies, has 2 voices.

Last updated by Shane 5 years, 4 months ago.

Assisted by: Shane.

Author
Posts
#1286485

Hello Shane,

As I told you in the first message, we used your solution posted here: https://toolset.com/forums/topic/required-cred-checkboxes/ on one form and it actually works. The problem is that it is not working with other forms. The other forms have the same type of checkboxes (those forms are used for posting premium posts, but all of them are created in the same way).

Out question wasn't if it works on our fields (because we saw it work). The question is: How can we make it work on other forms as well?

Thank you!

#1286495

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Valentine,

Could you let me see that other form, the one that you said it worked on ?

Thanks,
Shane

#1287439

Hello,

It is the form with the ID 25559 > Add New Opportunities Form User Paid Listing Basic (ID: 25559)
It creates posts in Business Opportunities CPT.

Thx!

#1287729

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Valentin,

I'm not sure how this even worked in the first place since we are working taxonomies.

I know our documentation shows this implementation for custom fields. Even your code here

function my_validation($field_data, $form_data)
{
//field data are field values and errors
list($fields,$errors)=$field_data;

//uncomment this if you want to print the field values
//print_r($fields);

//validate if specific form
if ($form_data['id']==25559)
{

//check if field is selected
if (empty($fields['wpcf-type_of_proposal']['value']))
{
//set error message for featured image
$errors['wpcf-type_of_proposal'] = 'Please Specify if you are looking to Buy or Sell';
}
}

//return result
return array($fields,$errors);
}

Works only for custom field. If you check the form you won't find any fields with the name "wpcf-type_of_proposal".

Even as you say in your initial message that it works on the page here.
hidden link

When I performed my testing the validation doesn't work at all.

Maybe if you can send a screenshot of this working I will try to see why i'm not seeing it working but your initial code doesn't work. Also from my understanding the validation hook doesn't cover taxonomies.

Thanks,
Shane

#1288575

Hello,

Can you please help us with the JS implementation to make one of those fields required?

Thx!

#1288749

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Valentin,

Just add this to your form's JS editor.

jQuery("input[name='type-of-proposal[]']").attr("required", "true");

Thanks,
Shane

#1288761

Hello,

This makes both of them required. We need a code to make only one of them required (the user must choose if he wants to sell or to buy, not both).

Thx.

#1288811

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Try this code instead,


jQuery(document).ready(function () {
    jQuery('.form-submit').click(function() {
      checked = jQuery("input[name='type-of-proposal[]']:checked").length;

      if(!checked) {
        alert("You must check at least one checkbox.");
        return false;
      }

    });
});