2

I have a Wufoo form that I wanted to populate one of the fields with a value directly from the query string

alt text http://www.balexandre.com/temp/2010-07-26_2057.png

the normal jQuery call for this does not get anything back

jQuery("#Field13")

so, all set using this, is just not accomplish

jQuery("#Field13").val( my_qs_value );

alt text http://cl.ly/1n5W/content

I'm using the Embed Javascript code from Wufoo (not the iframe), and the free account, I'm also using jQuery and not the dollar sign for calling the jQuery methods.

Any idea in what can I try? Or is there a setup that can place this by default?


Edited

From Chris answer I got everything to work, in the Wufoo javascript code I added the defaultValues parameter that would call a method returning the information I needed.

'defaultValues':'Field13=' + getQuerystring('pname',''),

and the getQuerystring method I took it from Blogging Developer site:

function getQuerystring(key, default_)
{
  if (default_==null) default_=""; 
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}

We can't access the Wufoo iFrame as it's wufoo domain and all tries will end up with a cross-domain error call. This is the best solution and the Wufoo way of doing it.

0

1 Answer 1

5

Check out our documentation on URL modifications for prefilling Wufoo forms: http://wufoo.com/docs/url-modifications/

Basically in the JavaScript embed code, you can pass an additional parameter to prefill fields: 'defaultValues':'field5=wufoo&field6=today'

It looks like in your case you'll need to pull them out of the URL using whatever server side technology you are using to serve the page, then popular the JavaScript parameters with that data.

The reason that jQuery can't get at the fields inside is because the form is inside an iFrame (even with the JavaScript embed method) and JavaScript can't look inside iframes like that. Also, the screenshot has jQuery("Field13"), which would need to be jQuery("#Field13") as you have in the text above, if the form was actually on the same page.

2
  • Hi chris, im a fan from your css tricks site, welcome to Stackoverflow :) - the image is wrong should be the code, ill change that... Will read and try your suggestion, the form is in worpress 3.0 acting as a sale contact form as my friend do not want to use foxycart as she have to pay a monthly fee.
    – balexandre
    Jul 27, 2010 at 17:16
  • accessing an iframe that is not in the same domain will just fire up the CrossDomain error jQuery("iframe").contents().find('#Field13').val();. I'm going to try the Wufoo url-modifications
    – balexandre
    Jul 27, 2010 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.