Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • montana 42 posts 63 karma points
    Mar 31, 2011 @ 02:25
    montana
    0

    foreach over post/get variables in python or xslt

    {preferably python} I just need to quickly to print out all request variables:

    This approach is rather weak:

    "http://our.umbraco.org/wiki/reference/umbracolibrary/requestquerystring"

    is there a library method that returns an array of request variables in key value pairs already prepared?

  • montana 42 posts 63 karma points
    Mar 31, 2011 @ 02:36
    montana
    0

    I'm sorry I should have put this in developers/xslt ... and I wouldn't double post but I've not had much luck editing in this forum to date.

    Can someone please move this to the appropriate section?

  • montana 42 posts 63 karma points
    Mar 31, 2011 @ 22:31
    montana
    0

    Here's a simple form debug python script - allows for simple verficiation of posted form values for rapid development. That is if you want to make sure your form values are getting posted correctly before you write a production form handler

    For this simple form:

    <corespin:Macro Alias="RequestVariables" runat="server" />

    <form action="" method="post">
    <input type="text" value='desu' id='desu' name='desu' />
    <input type="text" value='liek' id='mudkips' name='mudkips' />
    <input type="text" value='skippy' id='pb' name='pb' />
    <input type='submit' />
    </form>

     Create this Macro:

    import System
    import System.IO
    import sys
    import re #regular expressions
    import clr

    from System import *
    from System.IO import *
    from System.Text import *
    from System.Net import *
    clr.AddReference('System.Web')
    from System.Web.HttpContext import Current



    # super simple form validation
    #create a dictionary list of expected fields from form submission [make sure input field ids to match key names]
    allowed_fields = {
    'desu': '',
    'mudkips': '',
    'pb': ''
    };


    print '<pre>'


    print 'before processing'
    for key in allowed_fields:
    print key + '=' + allowed_fields[key]
    print ''

    requestType = Current.Request.RequestType
    if requestType=='POST':
    PostedForm = Current.Request.Form
    for key in PostedForm:
    print 'POST:' + key + '=' + PostedForm[key]
    key_exists = allowed_fields.has_key(key)
    if key_exists:
    allowed_fields[key] = PostedForm[key]


    print ''
    print 'after processing'
    for key in allowed_fields:
    print key + '=' + allowed_fields[key]

    print '</pre>'

    #simple

    You could of course extend this to print out discarded / invalid posted values as well for further validation.

     

Please Sign in or register to post replies

Write your reply to:

Draft