【发布时间】:2022-01-17 20:33:46
【问题描述】:
我正在尝试在提交联系表单后实施 Paypal 支付网关。
为此,我将表单数据存储在数据库中,并在付款完成后从保存的 ID 中检索数据。将该 db id 保存在隐藏字段中以发送到 paypal url。
我已尝试并返回值。但是当我在 wpcf7mailsent 中获取表单数据时,它是空的。
function action_wpcf7_submit( $array ) {
global $wpdb;
$wpcf7 = WPCF7_ContactForm::get_current();
$form_id = $wpcf7->id;
$submission = WPCF7_Submission::get_instance();
$invalid_fields = $submission->get_invalid_fields();
$posted_data = $submission->get_posted_data();
if ($form_id ==123 && empty($invalid_fields))
{
$first_name = $posted_data['first-name'];
$last_name = $posted_data['last-name'];
$parent_email = $posted_data['parent-email'];
$parent_phone = $posted_data['parent-phone'];
$duration = $posted_data['Duration'][0];
$total_price = $posted_data['total_price'];
$notes_requests = $posted_data['notes-requests'];
$studentcount = $posted_data['studentcount'];
$table_name = "store_subscription";
$result_check = $wpdb->insert($table_name, array('parent_guardian_firstname' => $first_name, 'parent_guardian_lastname' => $last_name, 'parent_guardian_email' => $parent_email,'parent_guardian_phone' => $parent_phone, 'subscription_duration' => $duration, 'total_price' => $total_price, 'notes_special_request' => $notes_requests) );
$lastid = $wpdb->insert_id;
if($result_check){
for($i=1;$i<=$studentcount;$i++){
$add_student_name = $posted_data['student_name_'.$i];
$add_current_grade_level = $posted_data['current_grade_level_'.$i];
$additional_student_table = "store_subscription_student";
if(!empty($add_student_name)){
$wpdb->insert($additional_student_table, array('store_subscription_id'=> $lastid, 'student_name' => $add_student_name, 'grade_level' => $add_current_grade_level));
}
}
//setting the store_subscriptin_id to retrieve the data from the paypal.
$posted_data['store_subscription_id'] = $lastid;
$posted_data['paypal_pg_redirect_url'] = "https://www.example.com/redirect-paypal/?id=$lastid&amt=$total_price";
return $posted_data;
}
}
}
add_filter( 'wpcf7_submit', 'action_wpcf7_submit');
add_action( 'wp_footer', 'mycustom_wp_footer' );
function mycustom_wp_footer() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( e ) {
console.log(e.detail);
if ( '123' == e.detail.contactFormId ) {
var paypal_pg_redirect_url = document.getElementById('paypal_pg_redirect_url').value;
console.log(paypal_pg_redirect_url);
///window.location.href = paypal_pg_redirect_url;
}
}, false );
</script>
<?php
}
未设置隐藏字段值。有人可以帮我设置隐藏字段值并在wpcf7mailsent中检索
注意:我试过hook before_send_mail,后来知道我们不能改变before_send_mail的值。所以然后我尝试了posted_data钩子也没有设置为隐藏字段的值。 store_subscription_id 是我要设置值的隐藏字段。请帮忙。
【问题讨论】:
-
据我研究,我认为这是不可能的,我已在会话中设置,然后检索到。
标签: php wordpress contact-form-7