I have to save form value into PHP session and want to keep save all form value until form submit:
I have trying like this:
$pattern = '';
if(isset($_REQUEST['submit'])) :
$s1 = $_REQUEST['step1'];
$s2 = $_REQUEST['step2'];
$s3 = $_REQUEST['step3'];
$s4 = $_REQUEST['step4'];
$pattern .= $s1.$s2.$s3;
$p_cat= $_REQUEST['p_cat'];
$_SESSION['mywine'] = $pattern;
$_SESSION['quantity'] = $_REQUEST['step4'];
if($p_cat == 'mixed')
$p_cat = 'red,white';
else $p_cat= $_REQUEST['p_cat'];
endif;
$my_wine = $_SESSION['mywine'];
$qun = $_SESSION['quantity'];
$args = array(
'post_type' => 'product',
'product_cat' => $p_cat,
'posts_per_page' => 3,
'meta_query' => array(
array(
'key' => 'product_score_pattern',
'value' => $my_wine,
'compare' => '='
)
)
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
endwhile;
endif;
This code able to save data into session but when I will refresh page then session value will be empty.
I want to keep form vale until form submit. How this will be possible?
You have to call
session_start()
before to assign or access$_SESSION
variable like below.Okay, you are using wordpress, it is not allowing create session.. you need to refer this
https://wordpress.org/support/topic/sessions-not-working-tried-everything
WordPress session management