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

    I'm very, very new to modx but enjoying it very much smiley

    I have a form with two steps. After the first form is completed, it gets redirected to another page where the user must login and then we should finish the second step to finish.

    All is working fine when the user is logged in but when the user is logged in the form values are cleared and the user goes back to the first form.

    First form:
    [[!FormIt@bmiCalculatorv2? &hooks=`redirect` &submitVar=`submit-bmi` &clearFieldsOnSuccess=`No` &store=`1` &storeTime=`300000`] &redirectTo=`22`]
    [[!FormItRetriever]]
    <div class="calc-container">
      <div class="atk-form">
        <form action="[[~[[*id]]]]" method="post" enctype="application/x-www-form-urlencoded" name="bmiCalc" id="bmiCalc">
          <fieldset>
            <div class="red-radios">
              <input type="radio" id="male" name="male">
              <label for="male" class="small-label">[[%atkins.bmi.gender.male? &namespace=`atkinswidgets` &topic=`bmi`]]</label>  
            </div>
            <div class="red-radios">
              <input type="radio" id="female" name="female">
              <label for="female" class="small-label">[[%atkins.bmi.gender.female? &namespace=`atkinswidgets` &topic=`bmi`]]</label>
            </div>
            <p class="hidden error" data-id="uniform-male,uniform-female">[[+fi.error.gender]]</p>
          </fieldset>  
          <fieldset>
            <label for="weight">[[%atkins.bmi.weight? &namespace=`atkinswidgets` &topic=`bmi`]]</label>
            <input type="text" name="weight:required" id="weight" value="[[+fi.weight]]">
            <span>kgs</span>   
            <p class="hidden error" data-id="weight" >[[+fi.error.weight]]</p>
          </fieldset>
          <fieldset>
            <label for="height">[[%atkins.bmi.height? &namespace=`atkinswidgets` &topic=`bmi`]]</label>
            <input type="text" name="height:required" id="height" value="[[+fi.height]]">
            <span>cms</span>  
            <p class="hidden error" data-id="height">[[+fi.error.height]]</p>
          </fieldset>
    
          <div class="btn-red">
            <span>
              <input type="submit" name="submit-bmi" value="[[%atkins.bmi.calcbmi? &namespace=`atkinswidgets` &topic=`bmi`]]">
            </span>
          </div> 
      </form>
      </div>
    </div>    

    ​
    Form 2
    [[!FormItRetriever? &placeholderPrefix=`fi.` &redirectToOnNotFound=`17`]]
    [[!FormIt? &submitVar=`nextstep` &hooks=`spam,redirect` &store=`1` &redirectTo=`20` &validate=`goal_weight:required`]]
    
    <div class="wrapper bmi-calc-results internal-page clearfix">
      <div class="wrapper-medium">
        <div class="text-block clearfix">
          <h2>Form Step 2</h2>
        </div>
        <div class="text-block wider clearfix">
          [[*longtitle:ne=``:then=`<h3>[[*longtitle:stripTags]]</h3>`]]
          [[*introtext:ne=``:then=`<p>[[*introtext:stripTags]]</p>`]]
        </div>
        [[!LoggedInBMI]]
    
        <!--END rect box-->
      </div>
    </div>


    LoggedInBMI snippet
    <?php
    $ctxs = !empty($ctxs) ? $ctxs : $modx->context->get('key');
    if (!is_array($ctxs)) $ctxs = explode(',',$ctxs);
    
    if (!$modx->user->hasSessionContext($ctxs)) {
        return '[[!Login@bmiLogin? &loginKey=`bmi-login` &loginResourceId=`22`]]';
    }
    return '[[$formBmiSaveResult]]';​


    formBmiSaveResult chunck
    <div class="simple-form gradient-divider atk-form">
      <form action="[[~[[*id]]]]" method="post" id="bmiStep3">
        <input type="hidden" name="gender" value="[[+fi.gender]]" />
        <input type="hidden" name="measurement_type" value="cms" />
        <input type="hidden" name="current_weight" value="[[+fi.current_weight]]" />
        <input type="hidden" name="current_height" value="[[+fi.current_height]]" />
        <input type="hidden" name="bmi" value="[[+fi.calculated_bmi]]" />
    
        <ul class="clearfix">
          <li>
            <label for="goal-value">[[%atkins.bmi.entergoalweight? &namespace=`atkins_widgets` &topic=`bmi`]]</label>
            <input type="number" value="" name="goal_weight" id="goal-value" value="[[+fi.goal_weight]]">
            <span class="sub-label">Kgs</span>
          <li>
            <span class="btn-red">
              <span>
                <input type="submit" name="nextstep" value="Save">
              </span>
            </span>
          </li>
        </ul>
      </form>
    </div>​


    So basically after the login all the values seem to be cleared from the cahce... Can anyone help?

    Thanks
      • 11055 ☆ A M B ☆
      • 3,112 Posts
      Quote from: jribeiro at Dec 18, 2012, 03:08 AM

      LoggedInBMI snippet
      <?php
      $ctxs = !empty($ctxs) ? $ctxs : $modx->context->get('key');
      if (!is_array($ctxs)) $ctxs = explode(',',$ctxs);
      
      if (!$modx->user->hasSessionContext($ctxs)) {
          return '[[!Login@bmiLogin? &loginKey=`bmi-login` &loginResourceId=`22`]]';
      }
      return '[[$formBmiSaveResult]]';​


      I believe you are about to initiate the snippet or chunk for the output?
      Well, try to use the API.
      <?php
      
      $ctxs = !empty($ctxs) ? $ctxs : $modx->context->get('key');
      if (!is_array($ctxs))
          $ctxs = explode(',', $ctxs);
      
      if (!$modx->user->hasSessionContext($ctxs)) {
          return $modx->runSnippet('Login@bmiLogin', array(
                      'loginKey' => 'bmi-login',
                      'loginResourceId' => 22
                  ));
      }
      return $modx->getChunk('formBmiSaveResult');​
        Rico
        Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
        MODx is great, but knowing how to use it well makes it perfect!

        www.virtudraft.com

        Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

        Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

        Maintainter/contributor of Babel

        Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
        • 42351
        • 4 Posts
        Thanks for the answer. As it seems, the login was reseting my session. I ended creating a backup of the formit form submission cache file and restoring it after login.

        This was a bit of a hack to the Login plugin but here it goes:

        Login Snippet before the authentication:
        $curSession = md5(session_id());
        $basePath = MODX_CORE_PATH . 'cache/' . $modx->context->get('key') . '/elements/formit/submission/';
        rename($basePath .$curSession . ".cache.php" ,$basePath . $curSession . ".cache.bck.php");


        and after:
        rename($basePath . $curSession . ".cache.bck.php" ,$basePath . md5(session_id()) . ".cache.php");


        Quote from: goldsky at Jan 06, 2013, 10:07 AM
        Quote from: jribeiro at Dec 18, 2012, 03:08 AM

        LoggedInBMI snippet
        <!--?php
        $ctxs = !empty($ctxs) ? $ctxs : $modx--->context->get('key');
        if (!is_array($ctxs)) $ctxs = explode(',',$ctxs);
        
        if (!$modx->user->hasSessionContext($ctxs)) {
            return '[[!Login@bmiLogin? &loginKey=`bmi-login` &loginResourceId=`22`]]';
        }
        return '[[$formBmiSaveResult]]';​


        I believe you are about to initiate the snippet or chunk for the output?
        Well, try to use the API.
        <!--?php
        
        $ctxs = !empty($ctxs) ? $ctxs : $modx--->context->get('key');
        if (!is_array($ctxs))
            $ctxs = explode(',', $ctxs);
        
        if (!$modx->user->hasSessionContext($ctxs)) {
            return $modx->runSnippet('Login@bmiLogin', array(
                        'loginKey' => 'bmi-login',
                        'loginResourceId' => 22
                    ));
        }
        return $modx->getChunk('formBmiSaveResult');​