Skip Navigation

[Resolved] can’t access select-field value in custom FormValidator

This thread is resolved. Here is a description of the problem and solution.

Problem:
can't access select-field value in custom FormValidator hook cred_form_validate

Solution:
You can use following code to validate the Toolset form.

add_filter('cred_form_validate','cred_filetype_size_validation',10,2);
function cred_filetype_size_validation($field_data, $form_data){
    list($fields,$errors)=$field_data;
    if ( 9999 == $form_data['id'] ) {
     
        echo "<pre>";
        print_r($_POST);
        print_r($fields);
        exit;
    }
    return array($fields,$errors);
}

You can find the proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/cant-access-select-field-value-in-custom-formvalidator/#post-1111409

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

This support ticket is created 6 years, 2 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
- 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 2 replies, has 2 voices.

Last updated by klausB 6 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#1110608

I am trying to: access a select-field value in my custom validator (https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate)

I expected to see: the ID of the post that is selected so i can get the related posts with this function: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post

Instead, I got: no value of the selected item

Here is the relevant part of the validator that I'm using:

add_filter('cred_form_validate','pkwFormValidation',10,2);
function pkwFormValidation($error_fields, $form_data)
{
    //field data are field values and errors
    list($fields,$errors)=$error_fields;
    
// this returns nothing (and yes there is a value selected in the form): 
    print_r($fields['@pkw-fahrzeugbuchung.parent']["value"]);
	(...)
}

this is the shortcode of the form:

[cred_field field='@pkw-fahrzeugbuchung.parent' class='form-control' output='bootstrap' select_text='Wählen Sie das Auto aus, das Sie reservieren möchten' value='[wpv-post-id]' ]

The shortcode above represents a relation to another post type. [wpv-post-id] in this context is the id of the related Post.

#1111409

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - I checked with the following code and I see the parent field value is displayed with $_POST AND $fields:

add_filter('cred_form_validate','cred_filetype_size_validation',10,2);
function cred_filetype_size_validation($field_data, $form_data){
    list($fields,$errors)=$field_data;
    if ( 9999 == $form_data['id'] ) {
	
		echo "<pre>";
		print_r($_POST);
		print_r($fields);
		exit;
    }
    return array($fields,$errors);
}

Where:
- Replace 9999 with your form ID

#1112063

$_POST did the trick. In this variable I get all the data.

But in $fields the value @pkw-fahrzeugbuchung.parent is not filled. thanks.