简体   繁体   English

如何在同一页面上显示来自 WSForm Wordpress 插件表单的 AJAX 发布数据?

[英]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.

相关问题 如何在Wordpress的同一页面上提交Ajax表单 - how to submit ajax form on same page in wordpress 当同一页面上有多个表单时,如何使用 AJAX 从一个表单发布数据? - How to POST data using AJAX from one form when there are multiple forms on the same page? $ .ajax提交表单时,如何从同一页面使用$ _POST获取表单数据 - How to get form data with $_POST from same page when it is submitted by $.ajax 如何从一页发布表单数据并在同一页面上检索? - How to post form data from one page and retrieve it on the same page? 对同一个 PHP 页面执行 AJAX 发布请求(Jquery 表单插件) - Perform AJAX post request to the same PHP page (Jquery Form Plugin) Yii:如何将“表单”中的数据值发布到同一页面 - Yii: How to post the data value from 'form' to the same page 如何让用户提交表单中的文本并将其AJAX输入到db并显示在同一页面上? - How to have user submit text in form and AJAX it to enter to db and show up on same page? PHP无法从jQuery AJAX表单提交中获取发布数据 - PHP Not Picking Up Post Data from jQuery AJAX Form Submit Wordpress 如何使用 Ajax 显示成功 insert_post() 返回的新数据? - Wordpress how to use Ajax to show new data returned from successful insert_post()? 如何通过插件在WordPress中修改“新帖子”表单? - How do I modify the New Post form in WordPress from a plugin?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM