PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, February 7, 2022

[FIXED] How to show-up AJAX post data from WSForm Wordpress plugin form on the same page?

 February 07, 2022     ajax, forms, php, plugins, wordpress     No comments   

Issue

I have WSForm Pro form management plugin installed on my Wordpress site. 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. 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:

// 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_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. If I could have my own AJAX script, I would want to modify it slightly to reload the whole page. 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?


Solution

Found a workaround in WSForm functionality! From "Edit Form" choose "Actions", "Add", "Redirect" and point the page's redirect to itself. Click to to see the screenshot



Answered By - lonaihal
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing