Copied to clipboard

Flag this post as spam?

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


  • Chris Davis 56 posts 74 karma points
    Feb 10, 2011 @ 05:11
    Chris Davis
    0

    Default field value from querystring

    Is it possible to set defualt field values from a querystring or any other way? It would be great to be able to pass values from a link of a different page to the form.

    Great work!

  • Josh Reid 182 posts 258 karma points
    Feb 10, 2011 @ 06:47
    Josh Reid
    1

    If using xslt to display an html form just use:

    <xsl:value-of select="umbraco.library:RequestQueryString('String key')"/>

    ie:

    <input type="text" name="queryStr" value="{umbraco.library:RequestQueryString('String key')}" />

    Or if using a .Net control, target the asp field at page load and set the text to the querystring:

    protected void Page_Load(object sender, EventArgs e)
            {
                queryStr.Text = Request.QueryString['String key'];
            }
  • Josh Reid 182 posts 258 karma points
    Feb 10, 2011 @ 06:58
    Josh Reid
    0

    Or in a Template in [@String key] format, ie:

    <umbraco:Macro Alias="myMacro" queryStr="[@String key]" runat="server"></umbraco:Macro>

    Think that should about cover it.

  • Jon Cuthbert 84 posts 173 karma points
    Feb 10, 2011 @ 15:29
    Jon Cuthbert
    0

    Chris, this is possible to do this inside the xslt file but each type of field (select, text, radio, checkbox) will have to be coded individually. Do you have a field type in mind that you want to set the default value from the query string?

    I'll use the Text field as an example using some of Josh Reid's code. Inside the <xsl:when test="name() = 'PliableText'"> statement, do something like:

    <xsl:variable name="defaultVal">
        <xsl:choose>
            <xsl:when test="string-length(umbraco.library:RequestQueryString('String key')) &gt; 0">
                <xsl:value-of select="umbraco.library:RequestQueryString('String key')" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="defaultValue" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    Then, when "defaultValue" is called inside that xsl:when, use $defaultVal instead.

    Jon

  • Chris Davis 56 posts 74 karma points
    Feb 10, 2011 @ 16:20
    Chris Davis
    0

    Awe yes, I see. Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft