Skip Navigation

[Resolved] Split: Split: Filter posts with two parents – Forms API help required

This support ticket is created 5 years, 1 month 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.

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 4 replies, has 2 voices.

Last updated by Minesh 5 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#1381633

It looks great!! Later I'll test it.

Can you split this ticket, I've another issue with Validation, but I'd like you go on with it as you already knows the wp-admin setup if needed.

I've add and edit Timeslots forms. Both have the Bus parent field to connect the timeslot with a Bus.

What I need is to validete it to be sure it is not empty.

I tried this code, but it doesn't work for me:

add_filter('cred_form_validate','my_form_validate',10,2);
function my_form_validate ($field_data, $form_data) {

  list($fields,$errors)=$field_data;

  if ($form_data['id']==217) {
    
    $bus = $_POST['@bus-timeslot_parent'];
    
    if (empty($bus))
    {
      log_me('Empty Bus');
      $errors['@bus-timeslot_parent'] = 'You have to select a Bus';
    } else {
      log_me('NO Empty Bus');
    }

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

What I would like to achive is that the user cannot submit the form if the parent field is not set. Another complications is that I have many forms on the same page.

This is the page:

/dispatch/admin-dashboard/

This is the form:

/wp-admin/post.php?post=217&action=edit&lang=en

This is the view that display forms:

/wp-admin/admin.php?page=views-editor&view_id=151

thanks for the assistance.

#1381823

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

The wp-admin access details you shared with the previous ticket is not working with I try to login as toolset user. Can you please send me that so I can troubleshoot this issue further.

#1382049

Minesh
Supporter

Languages: English (English )

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

Ok - I've checked on your install and I found that you added the form to some popup.

It seems you are working on the site when I currently working. This will not help and take more time to troubleshoot the issue further.

First of all, I suggest you should separate the code you added. I've created another code snippet "toolset forms hook" where you should add all forms related hook and remove it from your "custom-functions" code snippet. You should reply here when you stop working on the site and I will start to investigate further.

Actually, Toolset form submits the data using PHP, this means that once you submit the form your page needs to refresh in order for the validations to run and return the errors.

I see you added the form to popup and form is set to submit so it will submit the form and refresh the page.

I suggest, to add some JS/jQuery code to make the parent field required and based on that you should enable and dislable the submit button that will be a really easy way to do so.

#1382053

Thaks for your answer. Now we stop working on the website. I moved all the forms code to "toolset forms hook".

I like your suggestion about validate by jQuery. The difficulty is how to work on select2 select and that we have many forms on the same page. Can you help me with a jQuery example?

#1382081

Minesh
Supporter

Languages: English (English )

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

To implement the jQuery it needs custom code that is above and beyond the scope of our support policy.

However, I've added the following code to your form's JS box that will actually help you to locate the ID of your HTML select field. You can take it as reference:

jQuery(document).ready(function($){
  
 id =  $('select[name="@bus-timeslot.parent"]').prop('id');
 
});