Copied to clipboard

Flag this post as spam?

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


  • trfletch 598 posts 604 karma points
    Feb 18, 2010 @ 11:39
    trfletch
    0

    Add querystring value into doc2form field

    Hi,

    I have an Umbraco V4 website and on the site I have a vacancies page, the vacancies page list the vacancies then after each one has a link to the vacancy application form which is a form created using doc2form. One of the fields in the form is "Job you are applying for". I would like this to be automatically filled in depending on what job they try to apply for, I have added the relevant querystring to the link as follows:

    <a href="{umbraco.library:NiceUrl(1220)}?id={@nodeName}">Click here to apply for this vacancy</a>

    But how can I make this populate the doc2form field, is it possible? Or would I have to create some kind of custom form? (hopefully not because I am not a developer!)

  • dandrayne 1138 posts 2262 karma points
    Feb 18, 2010 @ 12:32
    dandrayne
    101

    I'd love to hear a good way to do this, as in the past I've used jquery/javascript like this:

    <xsl:variable name="property">
    <xsl:choose>
    <xsl:when test="umbraco.library:Request('property') &lt;= 0 or string(umbraco.library:Request('property')) = '' or string(umbraco.library:Request('property')) = 'NaN'"></xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="umbraco.library:Request('property')"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <script type="text/javascript">
    //<![CDATA[
    propertyToView = "]]><xsl:value-of select="$property" /><![CDATA[";
    //]]>
    </script>

    Then you've got a javascript variable with your querystring value that you can pass to doc2form like the following

    $('.viewingProperty_li input').val(propertyToView);

    Dan

  • trfletch 598 posts 604 karma points
    Feb 18, 2010 @ 13:33
    trfletch
    0

    Hi Dan,

    Thanks for the response, is your way not a good way to do it then? I'm a bit confused as to how I would use your method to get it to work with what I have already got or would you not recommend doing it your way? So far I have the following XSLT:

    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']">
        <xsl:sort select="@createDate" order="descending" />
     <div class="vacancy-text">
     <h2><xsl:value-of select="@nodeName"/></h2>
     <xsl:value-of select="data [@alias = 'jobdescription']" disable-output-escaping="yes"/>
    <a href="{umbraco.library:NiceUrl(1220)}?id={@nodeName}">Click here to apply for this vacancy</a>
     </div>
    </xsl:for-each>
  • dandrayne 1138 posts 2262 karma points
    Feb 18, 2010 @ 13:48
    dandrayne
    1

    I don't like relying on javascript for things like this, but it will work.  You'd just need to adjust my posted code to search for 'id' instead of 'property' as it does now, then you can prefill the value with javascript.  Doc2Form gives each list item that surrounds the input fields a class of

    documentProperty_li

    so you can target the specific inputs with javascript

  • trfletch 598 posts 604 karma points
    Feb 18, 2010 @ 18:36
    trfletch
    0

    Hi Dan,

    Thanks for the response, sorry I'm not really up on javascript. I think I understand second part, on my doc2form page I have some javascript code like this:

    $('.jobtitle_li input').val(jobTitle);

    But I am unsure as to where the XSLT you have shown goes, is it on my my vacancy list page and how does it add the right javascript parameter to the correct link?

  • dandrayne 1138 posts 2262 karma points
    Feb 19, 2010 @ 10:42
    dandrayne
    1

    Ok, so the code in my post above goes in a macro placed on the same page as your doc2form macro.  This ensures that when people visit the doc2form page the querystring is captured and passed to your javascript variable.  That's the first part, and is how it knows the id to pass to the js variable.   

    You can use the above javascript in an external script or in on-page, it's up to you.  It's jquery so will need to be placed inside a document ready call with the jquery library installed.  If you're not already using jquery you may want to do this another way, as it's 50kb of extra code just to do this.  You could do the second part (giving the input field the value of your new variable) in any js library, or with straight javascript if you prefer.

    Does this help?  I may have just confused things more, but you're very near to getting this working!

    Dan

  • trfletch 598 posts 604 karma points
    Feb 19, 2010 @ 12:01
    trfletch
    0

    Excellent I've now got it working, thanks once again Dan. I was just a little confused as to what went where. I thought the XSLT above was to replace what I had (the querystring bit) but it was to run in addition to it. As I said I don't really know javascript so I was struggling to understand what your code was trying to do but now it is all working I can see how it does work (if that makes sense!).

Please Sign in or register to post replies

Write your reply to:

Draft