I have created an endpoint with the following php code. The code is currently allowing me to receive the correct pdf but none of the information from the $page is populated in the pdf. The $page is a page that lists out results of a user using shortcodes I have created that require the user id as input. The page gets the current user id required via a GET query parameter (user=###). If I send the form from the page itself it works perfectly fine, but when I attempt to replicate the submission in this endpoint the pdf is not populated with the user data.
add_filter("wcra_postresults_callback" , "wcra_postresults_callback_handler");
function wcra_postresults_callback_handler($request){
$user_id = $request['StudentID'];
$project = strtolower($request['Project']);
$page = "https://mydomain.com.au/view-results-".$project;
$student = get_userdata($user_id);
$student_email = $student->user_email;
$unitcomplete = url_to_postid($page);
$pagetitle = get_the_title($unitcomplete);
$completereferrer = $page."/?user=".$user_id;
$formid = 0;
$requestorigin = $_SERVER['HTTP_ORIGIN'];
if ($requestorigin === "myapp") {
switch($project):
case 'b':
$formid = "b7cd306";
break;
endswitch;
// Form data (replace with actual field names and values)
$formData = array(
'post_id' => $unitcomplete,
'form_id' => $formid,
'referer_title' => $pagetitle,
'queried_id' => $unitcomplete,
'form_fields[emaildestination]' => $student_email,
'action' => 'elementor_pro_forms_send_form',
'referrer' => $completereferrer
);
// Initialize cURL
$ch = curl_init();
// Set request URL
curl_setopt($ch, CURLOPT_URL, "https://mydomain.com.au/wp-admin/admin-ajax.php");
// Set request method to POST
curl_setopt($ch, CURLOPT_POST, 1);
// Set POST data
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($formData));
// Dump current data for debug
echo json_encode($formData);
// Capture response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute request
$response = curl_exec($ch);
// Dump form response for debug
echo $response;
// Close cURL handle
curl_close($ch);
echo 'Results sent!';
}
}