Skip to content

Instantly share code, notes, and snippets.

@chaupt
Created March 16, 2011 23:27
Show Gist options
  • Save chaupt/873534 to your computer and use it in GitHub Desktop.
Save chaupt/873534 to your computer and use it in GitHub Desktop.
Sample of intercepting a submission to third party site, doing ajax submit to Webvanta first, getting a unique ID
<div id='contact_intro'>
<h1>Contact <span>Us</span></h1>
<p>Please complete the form below and click the Submit button at the bottom.</p>
<p>We&#8217;ll reply as soon as possible.</p>
</div>
<div id='contact_pod_error' class='sysmsg'><w:sysmsg /></div>
<div id='contact_pod_form' class="box-s1">
<form id='contact_form' action='OTHERSITES ACTION URL GOES HERE' method='post' autocomplete='off'>
<p><label>NAME</label>
<input type='text' id='contact_firstname' class='initial_focus' name='contact[firstname]' />
<input type='text' id='contact_lastname' name='contact[lastname]' />
</p>
<p class="alt"><label>COMPANY</label>
<input type='text' id='contact_company' name='contact[company]' />
</p>
<p><label>EMAIL</label>
<input type='text' id='contact_email' class='required' name='contact[email]' />
</p>
<p id='email2'><label>EMAIL</label>
<input type='text' id='contact_email2' name='contact[email2]' />
</p>
<p class="alt"><label>SUBJECT</label>
<input type='text' id='contact_subject' name='contact[subject]' />
</p>
<p><label>MESSAGE</label>
<textarea id='contact_message' rows='8' cols='80' class='required' name='contact[message]'></textarea>
</p>
<p class="alt">
<input type='hidden' id='contact_ajax' name='contact[ajax]' value='json' />
</p>
</form>
<button type="button" id="form_submit_button"><img src='/webvanta_theme_images/blog/button-submit.gif' alt="Send Your Message" /></button>
</div>
<script type="text/javascript">
$(function(){
$("#form_submit_button").click(function(){
var first_name = $("form #contact_firstname").val();
var last_name = $("form #contact_lastname").val();
$.post('/crm_receiver',
{
'form_id' : 'crm_id',
'email2' : '',
'ajax' : 'json',
'crm_id[crm][name]' : first_name + " " + last_name
},
function(d) {
if (d.status == 'ok') {
$("form #contact_subject").val(d.id || 'unknown id');
$("form:first").submit();
}
},
'json'
);
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment