We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 23050
    • 1,842 Posts
    Hi there,

    I use session to get some info from previous page into my form, with &sessionVars.

    I would like to delete this info after having sent form, or even after leaving form without sending form.

    I add
    $_SESSION[$varName] = '';
    at the end of the if here :
    	if($sessionVars){
    		$sessionVars = (strpos($sessionVars,',',0))?explode(',',$sessionVars):array($sessionVars);
    		foreach( $sessionVars as $varName ){
    			if( empty($varName) ) continue;
    			$varName = trim($varName);
    			if( isset($_SESSION[$varName]) && !empty($_SESSION[$varName]) )
    				$fields[$varName] = ( isset($fields[$varName]) && $postOverides )?$fields[$varName]:$_SESSION[$varName];
    				$_SESSION[$varName] = '';
    		}
    		
    	}



    Is that a good way to do what I want ? Should I use another way ?

    Thanks for your help ! wink

    Edit : Oops, didn’t test it well... now $_SESSION is not passed to the form, the data is not displayed in my form :/

    How can I empty my $_SESSION[$varName] ?
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You’ll have to specifically clear those values. The easiest would be for you to create a whole subarray ($_SESSION[’myarray’][’value1’], $_SESSION[’myarray’][’value2], etc) then you can just set $_SESSION[’myarray’] = ’’; or something similar to clear all of your custom session values without bothering the MODx values.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 23050
        • 1,842 Posts
        Thank you for your help. I tried with a subarray but what do I specify then in &sessionVars in eForm call ?

        I’m not pretty familiar with php so I don’t know how to change if($sessionVars)... in order to get subarray works.

        Plus, when using
        $_SESSION[$varName] = '';
        in eform.inc.php, the data in my session is not saved when going from previous to form page. So, data in session is not displayed anymore in the form.
          • 33372
          • 1,611 Posts
          I would just put your session-clearing code in a function and call it using an eForm event (probably eFormOnMailSent). Then all you have to do is to include the function before your eForm snippet call and add a parameter to execute it to the call (no need to edit the core eForm code). See the wiki for more info.
            "Things are not what they appear to be; nor are they otherwise." - Buddha

            "Well, gee, Buddha - that wasn't very helpful..." - ZAP

            Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
            • 23050
            • 1,842 Posts
            Ok, thank you, works fine with eForm event !

            Here is the code, it might help wink

            Before eForm call, I add the snippet : [[SupprimeSession]]

            Here is [[SupprimeSession]] code :

            <?php
            function eformdeletesession(){
            $_SESSION['quelBien'] = '';
            }
            ?>

            where quelBien is the value passed in &sessionVars

            In eForm, I add &eFormOnMailSent=`eformdeletesession`

            That’s it smiley

            Thank for your help !
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              I believe that you are supposed to always have "return true;" at the end of your eForm functions, so that eForm will finish processing itself. It didn’t cause you any trouble since your function is called late in the eForm process, but it might have unexpected results without it.

                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 23050
                • 1,842 Posts
                Ok, thank you to point it smiley
                  • 33372
                  • 1,611 Posts
                  Quote from: sottwell at Dec 12, 2007, 04:18 AM

                  I believe that you are supposed to always have "return true;" at the end of your eForm functions, so that eForm will finish processing itself. It didn’t cause you any trouble since your function is called late in the eForm process, but it might have unexpected results without it.
                  And actually I always add a return ’’; at the end of the snippet itself (outside of the function) to make sure that the snippet doesn’t return a value that appears in the page (e.g., "1").

                  So the full code would be:
                  <?php
                  function eformdeletesession(){
                  $_SESSION['quelBien'] = '';
                  return true;
                  }
                  return '';
                  ?>
                  
                    "Things are not what they appear to be; nor are they otherwise." - Buddha

                    "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

                    Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options