Pass value from one page to another page

Hello everyone.

I want to pass some the value of email from one page to another. I am using the MailClimp and WordPress as platform.

I try pass the value with POST as option.

In page 1:

<?php
session_start();
$_SESSION['varname'] = $var_value;` ?>

and inside the form :

name="varname" value=""

in page 2 :

<?php
session_start();
$var_value = $_POST['varname']; ?>

and inside the form :

name="varname"  value="<?php echo $_POST['var_value']; ?>"

But the value of email not show me… Any feedback or idea how can do that?

Thanks in advanced.

1 Like

You are loading it into $_SESSION not $_POST so that’s where you need to read it back from.

@felgall thanks for the response. i try to understand what you mean. In which part of code i do wrong?

$var_value = $_SESSION['varname'];

New updates :

1st page :

<?php
session_start();
$_SESSION['varname'] = $var_value; ?>

inside the form

name="varname" value=""

2nd page :

<?php
session_start();
$var_value = $_SESSION['varname'];?> 

inside the form :

name="varname" value="<?php echo $SESSION['varname'];?>"

but the problem still remaining. Not passed my email value.

In your first page when you assign

$_SESSION['varname'] = $var_value;

$var_value is not going to exist. It can’t exist because session_start(); is your first line of code. So, setting your session variable needs to come further down the page after $var_value has been assign a value.

So you think that need to remove? I am asking sorry, but i am newbie for this. I don’t have so strong dev skills. :frowning:
I try to pass the value with post…

I think we need to see your full code because you should be passing the variable as a POST variable but for some reason are using a SESSION variable. Just seeing these snippet of code isn’t allowing anyone to help you sufficiently.

1 Like

** First Page.**

 <?php
    session_start();
    $_SESSION['varname'] = $var_value;

    /**
     * The Template for displaying product archives, including the main shop page which is a post type archive.
     * Override this template by copying it to yourtheme/woocommerce/archive-product.php
     *
     * @author         WooThemes
     * @package     WooCommerce/Templates
     * @version     2.0.0
     */

    if ( ! defined( 'ABSPATH' ) ) {
        exit; // Exit if accessed directly
    }
    get_header('shop'); ?>
    <div id="wrapper">
        <div class="row">    
            <?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>
            <h1 class="page-title"><?php woocommerce_page_title(); ?></h1>
        </div>

    <div class="row">
              <div class="small-12 medium-10 large-10 columns" id="category-content">
                    <?php endif; ?>
                    <?php do_action( 'woocommerce_archive_description' ); ?>
                    <?php if ( have_posts() ) : ?>
                    <div class="breabcrumb-wrapper">
                                <?php
                                    do_action( 'woocommerce_before_shop_loop' );
                                ?>
                                <?php
                                    do_action( 'woocommerce_before_main_content' );
                                ?>
                    </div> <!-- end breadcrumb-wrapper -->

                    <div class="product-category">
                            <?php woocommerce_product_loop_start(); ?>
                                <?php woocommerce_product_subcategories(); ?>
                                <?php while ( have_posts() ) : the_post(); ?>
                                    <?php wc_get_template_part( 'content', 'product' ); ?>
                                <?php endwhile; // end of the loop. ?>
                            <?php woocommerce_product_loop_end(); ?>
                    </div> <!-- product-category -->


                    <?php elseif ( ! woocommerce_product_subcategories( array( 'before' => woocommerce_product_loop_start( false ), 'after' => woocommerce_product_loop_end( false ) ) ) ) : ?>
                        <?php wc_get_template( 'loop/no-products-found.php' ); ?>
                    <?php endif; ?>

                    <?php do_action( 'woocommerce_after_shop_loop' );?>
                   <?php do_action( 'woocommerce_after_main_content' ); ?>    

            </div>     <!-- category-content small-12 -->
            <div class="small-12 medium-2 large-2 columns" id="category-sidebar">
                    <?php get_template_part('woocommerce-parts/shop', 'sidebar'); ?>
            </div> <!-- end sidebar -->
      </div> <!-- /row  -->
    </div> <!-- / wrapper -->

    <div class="row">     
    <div id="landing-background">     
    <div class="landing-subscribe">     
         
      <form action="fs.us12.list-manage.com/subscribe/post?u=488a155bb6da9266f2d074392&amp;id=8be4a493de"  method="post" 
          id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" 
          class="validate medium-8 small-8 small-centered large-8 large-offset-3  medium-centered columns" target="_blank" 
          style=" text-algin:center;" novalidate>    

      <div class="small-12 medium-12 large-6 columns">
          <input type="email" placeholder="Email Address" name="varname"  value=""  class="required email" id="mce-EMAIL">
        </div>
         
         <div class="small-12 medium-12 large-6 columns">
            <a  target="_blank" name="subscribe" href="<?php echo get_page_link(6677);?>"  class="checkout-button alt wc-forward"/>  Sign Up  </a>
         </div>
      </form>
             
    <script type='text/javascript' src='//s3.amazonaws.com/downloads.mailchimp.com/js/mc-validate.js'></script><script type='text/javascript'>(function($) {window.fnames = new Array(); window.ftypes = new Array();fnames[0]='EMAIL';ftypes[0]='email';fnames[1]='FNAME';ftypes[1]='text';fnames[2]='LNAME';ftypes[2]='text';fnames[3]='MMERGE3';ftypes[3]='birthday';fnames[4]='MMERGE4';ftypes[4]='dropdown';}(jQuery));var $mcj = jQuery.noConflict(true);</script>
          
    </div> <!-- landing-subscribe -->
    </div><!--- end landing background -->
    </div> <!-- row -->
    <?php get_footer('shop'); ?>

and the 2nd page:

    <?php
    $var_value = $_SESSION['varname'];

    /*Template Name: Subscribe*/
    get_header('shop'); ?>

    <section>
    <div id="wrapper">
            <div class="row">
                <div id="landing-background"> 
                        <div class="landing-wrapper medium-9 large-7 medium-centered columns">     
                            <div class="land-form-text">
                                    <h2><?php the_field('landing_text');?></h2>
                            </div>
                        </div> 
                </div>
              </div><!-- / row -->

               <div class="row">   

  <div class="small-12 medium-7 large-5 columns land-left">     
             <link href="//cdn-images.mailchimp.com/embedcode/classic-10_7.css" rel="stylesheet" type="text/css">
    <style type="text/css">
      #mc_embed_signup{background:#fff; clear:left; font:14px Helvetica,Arial,sans-serif; }
      /* Add your own MailChimp form style overrides in your site stylesheet or in this style block.
         We recommend moving this block and the preceding CSS link to the HEAD of your HTML file. */
    </style>

    <div id="mc_embed_signup">
    <h2> <?php the_field('landing_form_text');?> </h2>
    <form action="fs.us12.list-manage.com/subscribe/post?u=488a155bb6da9266f2d074392&amp;id=8be4a493de" 
    method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
    <div id="mc_embed_signup_scroll">
    <div class="mc-field-group ">
      <div class="large-offset-1 large-10 columns">
        <input type="email" placeholder="Your email"  name="varname"  value="<?php echo $_SESSION['varname'];?>" class="required email" id="mce-EMAIL">
      </div>
    </div> <!-- mc-field-group -->
      <div id="mce-responses" class="clear">
        <div class="response" id="mce-error-response" style="display:none"></div>
        <div class="response" id="mce-success-response" style="display:none"></div>
      </div>    <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
        <div style="position: absolute; left: -5000px;" aria-hidden="true"><input type="text" name="b_488a155bb6da9266f2d074392_8be4a493de" tabindex="-1" value=""></div>
        <div class="row">
          <div class="medium-9 medium-centered columns large-9 columns">
           <input type="submit" value="Sign Up" name="subscribe" id="mc-embedded-subscribe-page" class="large-12 columns"> </input>
          </div>
        </div>
        </div>
    </form>

    <script type='text/javascript' src='//s3.amazonaws.com/downloads.mailchimp.com/js/mc-validate.js'></script><script type='text/javascript'>(function($) {window.fnames = new Array(); window.ftypes = new Array();fnames[0]='EMAIL';ftypes[0]='email';fnames[1]='FNAME';ftypes[1]='text';fnames[2]='LNAME';ftypes[2]='text';fnames[3]='MMERGE3';ftypes[3]='birthday';fnames[4]='MMERGE4';ftypes[4]='dropdown';}(jQuery));var $mcj = jQuery.noConflict(true);</script>
    <!--End mc_embed_signup-->   
                        </div>
                </div>
    </div><!-- wrapper -->
    </section>
    <?php get_footer('shop')?>

I have not yet looked through the whole thing, but what struck me at the beginning was that you are setting a session to a variable which has not been defined.

<?php
    session_start();
    $SESSION['varname'] = $varvalue;

If this is the start of the script, where has $varvalue been defined?

@SamA74 i update the code.

Thanks for posting your code. I note that both pages include a form. Can you explain what variable you are passing? I can’t seem to find $var_value…

Thank you too for the response. Yes i have 2 forms and i try to pass the value of email. From 1 page to another, but in some points of code i make some mistakes and i try to find them.

You have changed the name from $varvalue to $var_value at the start of the script, but the variable has still not been defined.

I think that i was little confused about the values and variables.
I make some wrongs. I have 2 forms so i need to pass the value of email with POST as option.

I think it would help understand if you were consistent in the variable nameso you have $_SESSION['varname'] = $varname; and $varname = $_SESSION['varname'];

However, $varname is set when the user enters their email address in the form, which is then posted to the manage.com website, so I’m not clear how you’re going to get the value across to the other page.

1 Like

I want to thank you all for the help, the true is that i was little confused in which way need to follow for pass the value between forms. Any other suggestion?

1 Like

I think we have a clearer idea of what you are trying to achieve, but we’re not quite there yet. :smile:

We seem to have page 1 which when the form is submitted goes to manage.com and the same thing with page 2, so how are page 1 and page 2 associated?

OK i create i wireframe for this. Now is clearer what i try to do?

Edit : If it can be possible it will be more helpful if a moderator add this screen in my original post, i can’t edit.

Thanks for explaining. The problem I see is that neither page has the email address for very long. As I say, in both cases it is Posted to manage.com once the form’s submit button is pressed. I’m not sure whether this can be achieved in PHP without a clumsy change in the flow. It might be (better) achieved using JavaScript.