admin管理员组文章数量:1122846
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 = ";.$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, ".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!';
}
}
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!';
}
}
Share
Improve this question
asked Jul 2, 2024 at 7:14
holty07holty07
11 bronze badge
1 Answer
Reset to default 0Unfortunately the answer to this question is simply that you cannot do this. curl will never resolve the shortcodes of your page before you submit the form.
本文标签:
版权声明:本文标题:rest api - What is different about using admin-ajax.php in an endpoint and just submitting a form from the front end? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736301828a1931312.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论