Using POST Data to Generate "Search Results"-esque Page

  • Profile Image
    Anthony
    Asked on February 28, 2014 at 02:22 PM

    Hello,

    I've figured out how to get my form to send POST data to the Thank You page, but now I'm trying to figure out how to make the page I want. Basically, I want the Thank You page to generate a list of articles/links from my website based on the checkbox selections a user makes in the form. In the example form, for instance, a user who checks "Lime Green Platypus" and "Hot Pink Koala" should be lead to a list of links/articles the contains at least one of those selections. The actual form that I'll be developing will have nearly 38 different selections. I've looked at a variety of search engine scripts, but can't seem to find one that works well with the JotForm POST data. 

    Does anyone have experience implementing a similar feature and have some advice to offer? Thanks. 

  • Profile Image
    EltonCris
    Answered on February 28, 2014 at 04:16 PM

    Hi Anthony,

    Maybe a condition would be of help.

    Example:

    $sampleChoice4[] = $_POST['sampleChoice4[]'];

    $articles = "http://www.mywebsite.com/articles.html";

    //condition of selections that contains with the following.

    if($sampleChoice4 == "Lime Green Platypus" || $sampleChoice4 == "Hot Pink Koala"){

    //redirect users to a specific URL

    header("location:$articles");

    }

    Hope this gives you idea. If there's anything else we could help or if I've missed something, please let us know here.

    Regards!

  • Profile Image
    atorretti
    Answered on February 28, 2014 at 05:16 PM

    Thanks for the tip. 

    I was avoiding URL redirects, because that would mean I'd have to have a different URL redirect for every combination of selections.

    In the example, for instance, there are three possible choices: Lime Green Platypus, Hot Pink Koala, and Neon Orange Komodo Dragon. If I were to do a different URL redirect for each combination...

    Platypus
    Koala
    Dragon
    Platypus, Koala
    Platypus, Dragon
    Koala, Dragon
    Platypus, Koala, Dragon

    That's 7 different redirects, and the number of possible combinations climbs quickly as choice selection increases. In the actual form, there are going to be 38 different options (and won't involve weird-colored animals).

    (38!/((38-1)!*1!))+(38!/((38-2)!*2!))+(38!/((38-3)!*3!))+ETC...+((38!/((38-38)!*38!))

    If I were to do a seperate URL redirect for each combination, that would be 339,004,314,123 different URLs and redirect conditions (if my math is right). I was hoping for a single page that would display different items based on what boxes are indicated as checked based on POST data. I know there's coding that can be done on the website side of things, but I'm relatively new to coding and was curious as to what other people have done. 

     

  • Profile Image
    EltonCris
    Answered on February 28, 2014 at 06:52 PM

    Hi,

    Sorry, I see your point. That would end up huge collection of different URLs :)

    Will this one help? I am using "echo" to post different text if the given condition matches to the selections. No more URL redirection this time. :)

    <?php $sampleChoice4 = $_POST['samplechoice4']; //get selections $arrlength=count($sampleChoice4);$name = $_POST['fullname3'][0]; //get name //condition of selections for($x=0;$x<$arrlength;$x++){ if($sampleChoice4[$x] == "Lime Green Platypus"){//show text elements for this specific condition echo "<p>Hello <b>$name</b>! Thank you for selecting Lime Green Platypu. Cheers! <br/> ";} else if($sampleChoice4[$x] == "Hot Pink Koala"){//show text elements for this specific condition echo "<p>Good choice $name! You have Selected Hot Pink Koala! Cheers! <br/> "; } else { //otherwise if no conditions matched echo "Nothing here..."; } } ?>

    You can also get the code here: http://pastebin.com/raw.php?i=0qXQSZdU

    I have cloned your form here and made an example. Please submit to test.

    http://form.jotformpro.com/form/40587296386974?

    Let us know if you have further questions.

    Regards!

  • Profile Image
    atorretti
    Answered on February 28, 2014 at 07:07 PM

    That's great. Do you know if only text can be shown, or can code be inputed as well?

  • Profile Image
    Cesar
    Answered on February 28, 2014 at 11:34 PM

    Unless my colleague Elton suggests otherwise. I do believe code is able to be used as on the example he has provided, he has different html tags formatiing the text as to further customize the answers. 

    Do let us know if you need further assistance. Thank you.

  • Profile Image
    atorretti
    Answered on March 04, 2014 at 07:16 PM

    So I've been making changes in order for it to fit the form I'm working on, and I'm wondering what $arrlength=count($sampleChoice4)  and ($x=0;$x<$arrlength;$x++ are for. Do they count the number of selections made? I'm not too clear on that.

     

  • Profile Image
    jonathan
    Answered on March 04, 2014 at 09:33 PM

    Hi,

    You can review the PHP count function here . The variable within the () is the array. The count function in the code gets the index count to determine the lenght.

    So the next code ($x=0;$x<$arrlength;$x++ dictates how many FOR loops  for($x=0;$x<$arrlength;$x++) will happen so that it can count the number of occurence of the selection.

    Hope this answers the question.

    Our colleague EltonCris is the better coder. I am sure he will correct this also if my explanation is wrong.

    Thanks!