[英]How to show-up AJAX post data from WSForm Wordpress plugin form on the same page?
I have WSForm Pro form management plugin installed on my Wordpress site.我的 Wordpress 站点上安装了WSForm Pro表单管理插件。 The plugin utilizes AJAX as the only method to post a form's data so that only the form's area is updated on submit, not the whole page.
该插件使用 AJAX 作为发布表单数据的唯一方法,以便在提交时仅更新表单区域,而不是整个页面。 On submit I need to show-up the form's data on the same page.
提交时,我需要在同一页面上显示表单的数据。
What I have done.我做了什么。 Through adding a function to functions.php of my theme I'm able to get the form's data as a session variable:
通过将 function 添加到我的主题的函数中
// Add action to process WS Form form data
add_action('wsf_action_tag', 'wsf_action_function', 10, 2);
// My function for action
function wsf_action_function($form, $submit) {
// Get submit value (Change '123' to your field ID)
$submit_value = wsf_submit_get_value($submit, 'field_18');
session_start();
$_SESSION['form'] = $submit_value;
// Do something with $submit_value here
// ...
}
I also added the following php-code to the page with the form to show-up the session variable above:我还在页面中添加了以下 php 代码,以显示上面的 session 变量:
<?php
session_start();
$form = $_SESSION['form'];
var_dump($form);
?>
The problem.问题。 When I submit the form, nothing changes except built-in success message (as supposed with AJAX), though on page reload the submitted data is shown-up successfully.
当我提交表单时,除了内置的成功消息(如 AJAX 所假设的那样)之外没有任何变化,尽管在页面重新加载时已成功显示提交的数据。 If I could have my own AJAX script, I would want to modify it slightly to reload the whole page.
如果我有自己的 AJAX 脚本,我想稍微修改一下以重新加载整个页面。 But since I use a third-party plugin, it's makes the task too complicated.
但是由于我使用了第三方插件,所以任务太复杂了。
The question is how would I change any part of my code to show-up the form's data on submit on the same page?问题是我将如何更改代码的任何部分以在同一页面上提交时显示表单的数据?
Found a workaround in WSForm functionality, From "Edit Form" choose "Actions", "Add".在 WSForm 功能中找到了一种解决方法,从“编辑表单”中选择“操作”、“添加”。 "Redirect" and point the page's redirect to itself.
“重定向”并将页面的重定向指向自身。 Click to to see the screenshot
点击查看截图
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.