Tip

Parse query from URL

Sometimes you need to parse a query string from the URL right in the form. One solution is to use a CGI server variable.




  1. Create a new computed when composed text field called query_string containing itself -- query_string. It causes a Web server to input content of the CGI Web server query_string variable (everything beyond the ? in the URL).
  2. Then create a new computed for display only multi-value text field called "parameters," for instance. This field should contain the following @Formula:
    @Explode(@Right
    (query_string; "&"); "&")
    
    This separates all name=value type sequences into multi-value ones and omits the URL commands beyond the ?.
  3. Then create two new computed for display multi-value text fields called "ParamNames" and "ParamValues," for instance, and containing the following @Formulas:
    @Word(Parameters; "="; 1) 
    and 
    @Word(Parameters; "="; 2)
    
    There are split values from names.
  4. Then it's possible to search for a particular name in ParamNames using:
    @If(@IsMember("Required_Name";
     ParamNames); @Subset(@Subset
    (ParamValues; @Member
    ("Required_Name"; ParamNames)); -1); 
    "Not present")
Function will return then the appropriate value or "Not present" (or anything else if you change it), if "key" name is not present in the URL. You can upgrade functionality by converting names to upper- or lowercase to avoid name variations. None of those fields, except query_string, will be saved, but this could be handled in web_query_save agent then.

Do you have comments on this tip? Let us know.

This was first published in November 2003

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.