Support » Plugin: Pods - Custom Content Types and Fields » Forms & Post ID

  • Resolved christap2019

    (@christap2019)


    Hi guys,

    I am new to PHP and in particular PODS.

    I am trying to create a job board site using PODS. I have created a new POD for candidates and another POD for jobs. On the front end a user will be on a job page and complete an application form which creates an entry onto the candidate page on the back end. My question is how do I pass on the id of the job page they are on so it links on the back end? My code is below for the form:

    <?php
    $mypod = pods( ‘candidate’ );

    // Only show the ‘name’, ‘description’, and ‘other’ fields.
    $fields = array( ‘first_name’, ‘last_name’, ’email_address’, ‘phone_number_1’, ‘cv’ );

    // Output a form with specific fields, custom label, and thank you URL
    // (with ID passed into it)
    echo $mypod->form( $fields, ‘Submit’, ‘/thank-you-for-submitting/?new_id=X_ID_X’ );

    ?>

Viewing 1 replies (of 1 total)
  • Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    The most secure way to do this would be to hook into the pre-save for that pod item and set it there: https://pods.io/docs/code/filter-reference/pods_api_pre_save_pod_item_podname/

    The other way you can do this is pre-populate the field and make it hidden:

    
    <?php
    $mypod = pods( 'candidate' );
    
    // Only show the ‘name’, ‘description’, and ‘other’ fields.
    $fields = [
    	'first_name',
    	'last_name',
    	'email_address',
    	'phone_number_1',
    	'cv',
    	'your_job_field_name' => [
    		'hidden' => true,
    		'value'  => get_the_ID(), // Set the value to the current ID.
    	],
    ];
    
    // Output a form with specific fields, custom label, and thank you URL
    // (with ID passed into it)
    echo $mypod->form( $fields, 'Submit', '/thank-you-for-submitting/?new_id=X_ID_X' );
    ?>
    
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.