php - WordPress Sessions - Sticky forms -


i don't understand wordpress programming using few online articles , looking though various forums (including one) i've managed set series of forms in own pages in wp. idea when first form completed data submitted second form page. page template 2nd page grabs data , stores in session variables later use (eg. display of data entered earlier reference purposes. using code shown below i've got working.

my problem want users able go second form page first form page edit data entered. think called 'sticky' form.

how achieve this?

currently, session code works if go forward in the series of form pages if navigate form 1 form 2 data lost.

in functions.php file i've got following code initiates session:

add_action('init', 'mystartsession', 1); add_action('wp_logout', 'myendsession'); add_action('wp_login', 'myendsession');  function mystartsession() {     if(!session_id()) {     session_start();     } }  function myendsession() {     session_destroy (); } 

in page templates form page 2 i've got code grabs incoming data page 1 , stores in session variables:

<?php  /*  template name: form page 2 */  $_session['text_1'] = $_request['text_1']; $_session['text_2'] = $_request['text_2']; $_session['text_3'] = $_request['text_3']; $_session['text_4'] = $_request['text_4'];   get_header();   ... etc. 

on form page 1 have used plugin allow me insert php code snippets shortcodes.

in textarea on form page 1 i've added shortcode contains following php:

<textarea id="text_1" name="text_1" required rows="5">[php snippet=9]    </textarea> 

shortcode code (snippet=9):

if (isset($_session['text_1'])) {    echo $_session['text_1']; } 

this works when moving form page 1 form page 2 (data in session variables can accessed but, if go (say, i'm on page2 , want go edit data on page 1) data lost (it doesn't show in textarea).

i'm not sure if correct way use sessions in wp or whether there better way this.

hoping can me.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -