We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6094
    • 60 Posts
    I hope I can make this clear, please bear with me.

    I would like to populate a text field value with a value pulled from a URL query string. I am creating a registration form for various courses. Currently, I have a page displaying all the available courses, their dates and locations. When a user clicks on the corresponding registration link I would like them to be taken to a form for registration, using eForm.

    I have my link working correctly now it will send the following information:
    http://www.somepage.com/registration-page?cn=course name&cd=course date&cl=course location

    On the registration page I have been able to display the information back to the page using the following snippet
    <?php
    /*    testsnippet
          usage: call uncached
          [!testsnippet!]
    
    */
    $output ='';
    $cdate = isset($_GET['cd']) ? $_GET['cd'] : 'cdate not found';
    $cname = isset($_GET['cn']) ? $_GET['cn'] : 'cname not found';
    $clocation = isset($_GET['cl']) ? $_GET['cl'] : 'clocation not found';
    
    $output .='<p><strong>Course Date:</strong> '.$cdate.'</p>';
    $output .='<p><strong>Course Name:</strong> '.$cname.'</p>';
    $output .='<p><strong>Course Location:</strong> '.$clocation.'</p>';
    
    
    return $output;
    ?>
    


    I tried to use something similar for my form field, but it doesn’t work correctly. For instance if the course was called "Jumping Jacks", the form field would only be populated with "Jumping". It seems that as soon as it hits a space in the string it terminates.

    Has anyone successfully done something like this? Any help would be greatly appreciated.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      URLs should not have spaces. They should get encoded using urlencode() (which converts spaces to +) or to %20. Browsers can handle spaces (well, most modern ones can...of course IE 6 will as usual be a problem), but the results of spaces in other contexts may be unpredictable (as you have noticed).

      GET values have already been urldecoded; never use urldecode() on $_GET values.

      You can also replace all spaces with something such as _ (Jumping_Jacks) while generating the URL, then replace the _ with spaces in your GET processing code.
        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
        • 6094
        • 60 Posts
        Thanks so much for the info. I’m at a bit of a loss, not being a true PHP programmer. I will fumble my way through it and see if I can make it work.