开发者

Pass data to a FORM and auto submit it

The thing I'm trying to have is a JQuery/JavaScript code that will automatically pass some data from facebook to a form (basically the form doesn't need to be shown). so the first part is ready (the part that pulls the data from facebook).

      window.fbAsyncInit = function() {
  FB.init({appId: 'xxxxxxxxxxxxxxx', status: true, cookie: true, xfbml: true});
      };
    FB.Event.subscribe('auth.login', function(response) {
         if (response.session) {
         FB.api({
         method: "fql.query",
         query: "SELECT name,email FROM user WHER开发者_运维技巧E uid = " + response.session.uid
            }

Now i need to insert the name and the email to the inputs with name="name" and name="email" and auto submit the form.

Thanks in advance!

EDIT: here is the form:

<form method="post" class="af-form-wrapper" action="http://www.aweber.com/scripts/addlead.pl"  >

<input type="hidden" name="meta_web_form_id" value="XXXXXXXX" />
<input type="hidden" name="listname" value="XXXXXX" />
<input type="hidden" name="meta_adtracking" value="XXXX" />
<input type="hidden" name="meta_message" value="1" />

<input id="awf_field-22176678" type="text" name="name" class="text" value=""  tabindex="500" />

<input class="text" id="awf_field-22176679" type="text" name="email" value="" tabindex="501"  />

<input name="submit" class="submit" type="submit" value="Submit" tabindex="502" />
<div class="af-clear">

</form>

EDIT 2: I need to do something like this just simplified with jQuery:

        <?php
        $formcode = '<form method="post" action="http://www.aweber.com/scripts/addlead.pl"  >

<input type="hidden" name="meta_web_form_id" value="864136470" />
<input type="hidden" name="listname" value="fbu-ppv-mmoney1" />
<input type="hidden" name="meta_adtracking" value="FB_Ultralizer_PPV" />
<input type="hidden" name="meta_message" value="1" />

<input id="awf_field-22176678" type="text" name="name" class="text" value=""  tabindex="500" />

<input class="text" id="awf_field-22176679" type="text" name="email" value="" tabindex="501"  />

<input name="submit" class="submit" type="submit" value="Submit" tabindex="502" />

</form>
'; ?>
<script type="text/javascript">
                                                customar_formcode="$formcode";
                                                customar_formcode=customar_formcode.replace("{email}", user.email);
                                                customar_formcode=customar_formcode.replace("{name}", user.name);
                                                document.getElementById(\'form\').submit();
</script>


Use Jquery's POST to send the data without the need for the markup for a form and using auto submits:

$.ajax({
  type: 'POST',
  url: url,
  data: data,
  success: success,
  dataType: dataType
});

EDIT: If you have already got the form setup in the DOM you should just fill it in with JavaScript and submit it with JavaScript

To change the input values use Jquery like so:

$('input[name$="name"]').val('value');

once all the inputs are set to how you want them you can submit the form using this:

if you have the ID form on your form then you can use code like

$('#form').submit();

Hope this helps


with jquery you can pass all data of form at once with something like: var data = $(#formID).serialize();

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜