• Resolved kitsufox

    (@kitsufox)


    I’m working on writing a PHP based form for a website using pods. I want to be able to use a customized WHERE set via the PHP instead of the dialog box for setting up the field. I’ve done some searching but can’t find anything that says I can or can’t do this.

    'group_membership' => array( 'description' => 'MATCH TO OLD GROUP!
    This will activate the new system for this character.','customized_where' => 'secret.meta_value != 1' )

    So, if it’s possible, what do I call when I put it in the array where I’ve currently tried ‘customized_where’? I hope this works so that I can have multiple versions of the same form that only let the end user select from a limited list of options based on that customized where.

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

    (@sc0ttkclark)

    Can you clarify what you are passing that PHP into?

    You should try out using our find() method on the Pods object: https://docs.pods.io/code/pods/find/

    Thread Starter kitsufox

    (@kitsufox)

    I’m passing it into form().

    Here’s the complete bit of code that might clarify what I’m attempting.

    $charpod = pods( 'characters', $charid )
    $fields = array(
    'group_membership' => array( 'description' => 'MATCH TO OLD GROUP!
    This will activate the new system for this character.','customized_where' => 'secret.meta_value != 1' ),
    'rank_assignment' => array( 'description' => 'MATCH TO OLD RANK!
    This will activate the new system for this character.' )
    );
    echo $charpod->form($fields);

    Specifically, I want to be able to set the field setting “customized WHERE” in the advanced setting for a relationship field. But I’m not sure there’s a way to accomplish this dynamically based on what version of the form the end user is sent to?

    • This reply was modified 7 months, 1 week ago by kitsufox.
    Plugin Support Paul Clark

    (@pdclark)

    @kitsufox Parameters for a relationship field do not have a where argument because a query is not run — the specific IDs are stored.

    However, one can override what items display as options in a relationship field by adding a query using the pods_field_pick_data filter or pods_field_pick_data_ajax filter

    This filter will run for all relationship fields on frontend and backend, so one can either attach the filter based on admin or frontend context, or modify behavior based on the field $name or other information passed to the function.

    An example of using the first filter:

    <?php
    add_filter(
    'pods_field_pick_data',
    function( $data, $name, $value, $options, $pod, $id ) {
    error_log(
    print_r(
    [
    'info' => sprintf( 'RELATIONSHIP FIELD named %s', $name ),
    '$data' => $data,
    '$name' => $name,
    '$value' => $value,
    '$options' => $options,
    '$id', => $id,
    ]
    true
    )
    );
    return $data;
    },
    10,
    6
    );

    …where return $data sends the data to the field unmodified in all cases, while print_r() saves information for every relationship field that ran the filter to the PHP error log. $pod was left out of logging, as it would be an instance of the Pods object, which contains a lot of information.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Set customized where using PHP when calling a form’ is closed to new replies.