We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10378
    • 375 Posts
    I'm using a profile update form with the post method and with an additional URL parameter:

    [[!UpdateProfile?
        &useExtended=`0`
        &validate=`email:email:required,
            nospam:blank`
    ]]
    <form action="[[~[[*id]]]]?val=somevalue" method="post">
    ...
    


    If the form is validated successfully the UpdateProfile snippet correctly redirects to itself but the GET parameter "val=somevalue" of the form isn't transported. The snippet only sets the parameter updpsuccess=1

    How can I get the UpdateProfile snippet to preserve the "val=somevalue" parameter?

    Thanks,
    Martin

    This question has been answered by TheBoxer. See the first response.

      Freelancer @bitego http://www.bitego.com
      ---
      GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
      More infos here: http://www.bitego.com/extras/goodnews/
      • 29661
      • 116 Posts
      Do you need the value of val variable only when the form is filled successfully, or everytime, when the form is sent (doesn't matter if the validation succeed or not) ?
        --
        John
        @theboxer
        • 10378
        • 375 Posts
        Quote from: TheBoxer at Sep 17, 2013, 12:38 PM
        Do you need the value of val variable only when the form is filled successfully, or everytime, when the form is sent (doesn't matter if the validation succeed or not) ?

        Yes - I need to preserve the value every time the form is sent. But only if the form is validated successfully the val variable isn't transported. If validation fails it works as expected.
          Freelancer @bitego http://www.bitego.com
          ---
          GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
          More infos here: http://www.bitego.com/extras/goodnews/
          • 29661
          • 116 Posts
          The redirect post hook could be a workaround. I am not sure why is not preserving the get params when validation succeed...
            --
            John
            @theboxer
            • 10378
            • 375 Posts
            Quote from: TheBoxer at Sep 17, 2013, 01:16 PM
            I am not sure why is not preserving the get params when validation succeed...

            I think the problem is, that the UpdatProfile snippet adds its on URL parameter updpsuccess=1 if validation was successful.
            If you look at line 21 of the code part below (extracted from the UpdateProfile.php controller from Login add-on) you can see, that a new url string is generated and existing parameters are ignored (if I understand the code correctly).

                /**
                 * Handle the UpdateProfile snippet business logic
                 * @return string
                 */
                public function process() {
                    if (!$this->verifyAuthentication()) return '';
                    if (!$this->getUser()) return '';
                    if (!$this->getProfile()) return '';
                    
                    $this->setFieldPlaceholders();
                    $this->checkForSuccessMessage();
                    if ($this->hasPost()) {
                        $this->loadDictionary();
                        if ($this->validate()) {
                            if ($this->runPreHooks()) {
                                /* update the profile */
                                $result = $this->runProcessor('UpdateProfile');
                                if ($result !== true) {
                                    $this->modx->toPlaceholder('message',$result,'error');
                                } else if ($this->getProperty('reloadOnSuccess',true,'isset')) {
                                    $url = $this->modx->makeUrl($this->modx->resource->get('id'),'',array(
                                        $this->getProperty('successKey','updpsuccess') => 1,
                                    ),'full');
                                    $this->modx->sendRedirect($url);
                                } else {
                                    $this->modx->setPlaceholder('login.update_success',true);
                                }
                            }
                        }
                    }
                    return '';
                }
            
              Freelancer @bitego http://www.bitego.com
              ---
              GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
              More infos here: http://www.bitego.com/extras/goodnews/
              • 29661
              • 116 Posts
              Yes, you are absolutely right, the code ignore every get param. So if you don't want to change core of Login extra, the best way should be the post hook, that will do the same as line 21 + it will add another param that you want (OR add all GET params that was sent).
                --
                John
                @theboxer
                • 10378
                • 375 Posts
                Quote from: TheBoxer at Sep 17, 2013, 01:30 PM
                Yes, you are absolutely right, the code ignore every get param. So if you don't want to change core of Login extra, the best way should be the post hook, that will do the same as line 21 + it will add another param that you want (OR add all GET params that was sent).

                I have currently no idea of how to write this postHook. Any hint?
                  Freelancer @bitego http://www.bitego.com
                  ---
                  GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
                  More infos here: http://www.bitego.com/extras/goodnews/
                  • 10378
                  • 375 Posts
                  I just tried to transport the value through a hidden input:

                  <input type="hidden" name="val" value="somevalue">


                  But also didn't work.
                    Freelancer @bitego http://www.bitego.com
                    ---
                    GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
                    More infos here: http://www.bitego.com/extras/goodnews/
                  • discuss.answer
                    • 29661
                    • 116 Posts
                    You can pass postHooks param to UpdateProfile snippet call, so you need to create a snippet that will do the redirect.

                    Basicaly create snippet called UpdateProfileRedirect (for example) and paste this code in it:
                    $url = $this->modx->makeUrl(
                        $this->modx->resource->get('id'),
                        '',
                        array(
                            $this->getProperty('successKey','updpsuccess') => 1,
                            'val' => 'someValue',
                        ),
                        'full'
                    );
                    $this->modx->sendRedirect($url);


                    And then add to your UpdateProfile &postHooks=`UpdateProfileRedirect`.

                    This is just basic snippet, you can improve it using value from hidden field (tutorial for retrieving fields from hook can be found here http://rtfm.modx.com/extras/revo/login/login.tutorials/login.using-pre-and-post-hooks) or you can try to access UpdateProfile parameters from the hook, but I don't know at this moment how to do it.

                    It could be similair as in FormIT ($hook->login->config['option']), but this is just a guess.
                      --
                      John
                      @theboxer
                      • 10378
                      • 375 Posts
                      Wow thanks a lot! Will try this and post back!

                      I think this behavior should be part of the UpdateProfile snippet so I'll also post a feature request at MODx tracker - or even try to create a pull request for this code on GitHub...
                        Freelancer @bitego http://www.bitego.com
                        ---
                        GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
                        More infos here: http://www.bitego.com/extras/goodnews/