We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34197
    • 138 Posts
    Hello.


    I am trying to create a form that redirect the visitor to a different page regarding the details he has entered into the form.

    Let's say there is a radio check box, the person tick "I like chocolate", he will be redirected to buy chocolate.


    Can this be done with "redirectParams" ?

    Thanks.
      Webdesigner and musician.
      • 14883 ☆ A M B ☆
      • 450 Posts
      I was just wondering a similar question. My form has a hook that creates a new object - then I want to use redirectParams to send users to a "view object" page with the ID of the newly created object. I'm going to create a new post and reference yours, because I think the answers to both questions will be essentially the same.
        • 14883 ☆ A M B ☆
        • 450 Posts
        I just figured out the solution, without needing to create a new forum post.

        The trick is to use a custom hook to set a placeholder, then pass that placeholder into the redirectParams.

        [[!FormIt?&hooks=`mySetter,redirect`&redirectTo=`123`&redirectParams=`{"product":"[[!+product.id]]"}`]]


        Assuming you get the product ID from a field called 'productID', your 'mySetter' custom hook snippet would look like this:

        $product = $hook->getValue('productID');
        $modx->setPlaceholder('product.id', $product);
        return true;
        


        The result would be that the redirect would take you to page 123 with a query string of "?product=3".

        Let me know if this works or if you need more help.
          • 34197
          • 138 Posts
          Hi jrotering, and thanks for you answer.


          I understand that you created a snippet called "mySetter", and regarding the value selected, some product will appear on the redirect page.


          My question what are those products ? How do you create them ? Are they TVs ?


          Thank you
            Webdesigner and musician.
            • 14883 ☆ A M B ☆
            • 450 Posts
            Hi Carlo,

            I haven't actually done a site that deals with selling products - I just used that as an example since your original question seemed to be about products. But here are some thoughts.

            First, no matter how you handle storing your product data, the "product" page you redirect to is going to need a snippet that reads the query string and gets the product ID.

            How to best manage your product data depends (in my opinion) on how large/complex your product catalog is. If you have only a dozen or so products, you could use MODX resources to hold your product data. Create a Template that has TVs for each bit of product data - description, price, category, etc. Your Product ID would be the resource ID of the product page, and you could use getResources or straight API code to load the product data.

            (Actually, if you used resources and a "Product" Template/TVs to manage your product catalog, you'd probably just go directly to the actual product page rather than the way my example does it - instead of
            &redirectTo=`123`&redirectParams=`{"product":"[[!+product.id]]"}`
            you would just use
            &redirectTo=`[[!+product.id]]`

            )

            For a larger, more complicated product catalog, it would make more sense to use a custom database or at least a custom db table. You could use native PHP code to access your product data from the DB, or use MODX's xpdo functionality to create a schema and classes based on your custom db and deal with your products as objects. That goes beyond the scope of this thread but there is documentation out there and you could find more help on the forums if that's the direction you need to go in.

            Hope this helps.
              • 34197
              • 138 Posts
              Thanks for your help again.
                Webdesigner and musician.
                • 3866 ☆ A M B ☆
                • 350 Posts
                Hi there,
                I have followed your hook snippet but it doesn't appear to be returning the value, here is my code:

                [[!FormIt? &hooks=`ReferralRedirect,redirect` &vTextRequired=`All fields must be completed` &validate=`firstname:required,lastname:required` &store=`1` &redirectTo=`[[!+formReferral]]`]] 


                And the value in the form that I'm trying to make use of:

                <input type="hidden" name="referral[]" value=""/>
                      <input type="radio" name="referral[]" value="36"><label>Self Referral</label> <br/>
                      <input type="radio" name="referral[]" value="37"><label>Professional Referral</label>


                And finally the snippet:

                $value = $hook->getValue('referral');
                $modx->setPlaceholder('formReferral', $value);
                return true;


                The form fires if I put an ID directly into &redirect but I seem unable to get the value based on the the radio selected. Where am I going wrong? smiley
                  Helen Warner
                  Number one pixel!
                  Proud to be linked with MODX at Crimson Pixel
                  • 4172
                  • 5,888 Posts
                  Hi Helen,

                  I think this shouldn't be an array, should it?

                  <input type="hidden" name="referral" value=""/>
                  <input type="radio" name="referral" value="36"><label>Self Referral</label> <br/>
                  <input type="radio" name="referral" value="37"><label>Professional Referral</label>


                  and another way to get this done:

                  create a wrapper - snippet for formit:

                  $scriptProperties['redirectTo'] = $modx->getOption('referral',$_POST,'');
                  $modx->runSnippet('FormIt',$scriptProperties);
                  return '';


                  and replace the formit-call with that wrapper-snippet.



                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 3866 ☆ A M B ☆
                    • 350 Posts
                    Hey Bruno,

                    Thanks for quick response. Removed the array but it still didn't work.

                    I'll try the wrapper snippet option and let you know how I get on.

                    UPDATE: Ok I'm either not getting this or it doesn't work.

                    I've added snippet call as suggested, and replaced the Formit call with the following:

                    [[ReferralRedirect]]


                    but that produced nothing.

                    Then added the formit properties from before as:

                    [[!ReferralRedirect? &submitVar=`go` &hooks=`redirect` &vTextRequired=`All fields must be completed` &validate=`firstname:required,lastname:required,phone:required,mobile:required,gp:required` &store=`1` &redirectTo=`[[!+formReferral]]`]] 


                    But still no joy.

                    I do need to store info from this first form across to the next form depending on whether a self referral or a professional referral. Did come across this post forums.modx.com/thread/80110/formit-redirect-regarding-radio-button-selected but that didn't seem to want to work either! and that did work once I changed some of my parameters as follows:

                    <?php
                    $value = $hook->getValue('referral');
                    switch ($value) {
                        case 'self':
                            $url = $modx->makeUrl(36);
                            $modx->sendRedirect($url);
                            break;
                        case 'professional':
                            $url = $modx->makeUrl(37);
                            $modx->sendRedirect($url);   
                            break;
                    }
                     
                    return;


                    [[!FormIt? &submitVar=`go` &hooks=`ReferralRedirect,redirect` &vTextRequired=`All fields must be completed` &validate=`firstname:required,lastname:required,phone:required,mobile:required,gp:required` &store=`1` ]] 


                      
                    
                        <input type="hidden" name="referral" value=""/>
                          <input type="radio" name="referral" value="self"><label>Self Referral</label> <br/>
                          <input type="radio" name="referral" value="professional"><label>Professional Referral</label>


                    UPDATE: This does send you to different pages based on radio selection but now it doesn't store the data across... [ed. note: boomerang last edited this post 12 years, 9 months ago.]
                      Helen Warner
                      Number one pixel!
                      Proud to be linked with MODX at Crimson Pixel
                      • 3866 ☆ A M B ☆
                      • 350 Posts
                      Of course this could be yet another way of achieving this https://forums.modx.com/index.php?topic=65211.0 !

                      Another way to skin the cat!!
                        Helen Warner
                        Number one pixel!
                        Proud to be linked with MODX at Crimson Pixel