• Resolved mpluss

    (@mpluss)


    My function pods_api_pre_save_pod_item is simple, I only put wp_die to throw an error and prevent post creating or updating. But, the creation of a new “famille” is always done, and all the fields are empty.

    
    add_filter('pods_api_pre_save_pod_item_famille', 'check_unique_field_identifiant_famille', 10, 2); 
    function check_unique_field_identifiant_famille($famille, $is_new_item) {
        wp_die( 'Identifiant famille existe déjà !');
    }
    

    Thanks for your help !

    WordPress Version: 4.9.8
    PHP Version: 7.1.21
    Pods – Custom Content Types and Fields: 2.7.9

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Scott Kingsley Clark

    (@sc0ttkclark)

    You’d want to use the validation hook for that.

    
    add_filter( 'pods_api_field_validation', 'my_validation', 10, 7 );
    
    function my_validation( $validate, $value, $field, $object_fields, $fields, $pod, $params ) {
    
        // Don't do anything if it is not the pod we want to check.
        if ( 'famille' !== $pod['name'] ) {
            return $validate;
        }
    
        // Don't do anything if it is not the field we want to check.
        if ( 'my_field' !== $field['name'] ) {
            return $validate;
        }
    
        // Do something, determine an error needs to be sent.
        return 'Identifiant famille existe déjà !';
    
    }
    
    Thread Starter mpluss

    (@mpluss)

    Merci !

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘cannot prevent pods_api_pre_save_pod_item_{podname}’ is closed to new replies.