Create New Record from Form Submission using Add

Real life example of a function to create a Pods record from fields submitted on a form.

<?php 
function add_new_applicant () { 

    // Get field values from form submission 
    $first_name = $_POST['first_name'] 
    $last_name = $_POST['last_name'] 
    $telephone = $_POST['telephone'] 
    $email = $_POST['email'] 
     
    $fields = array( 
        'first_name'    => $first_name, 
        'last_name'        => $last_name, 
        'telephone'        => $telephone, 
        'email'            => $email 
    ); 
                     
    $new_id = pods( 'applicant' )->add( $fields ); 
     
    return $new_id; 
}

Could also have a run through pods_sanitize to make sure the data is safe to be added.

pods('applicant')->add ( pods_sanitize ( $fields ) );

Questions