Skip to content

Instantly share code, notes, and snippets.

@bolak
Created February 15, 2017 18:01
Show Gist options
  • Select an option

  • Save bolak/857ed65860c38b7b0d40e20ee9b1747c to your computer and use it in GitHub Desktop.

Select an option

Save bolak/857ed65860c38b7b0d40e20ee9b1747c to your computer and use it in GitHub Desktop.
Registration POST request example.
$('.sign-up-form__registration-form').submit(function(e) {
$("#password-error").remove();
var form = this;
var formData = {
firstName: $('input[name=first]', form).val(),
lastName: $('input[name=last]', form).val(),
email: $('input[name=email]', form).val(),
dob: $('select[name=dob]', form).val(),
password: $('input[name=password]', form).val(),
passwordConfirmation: $('input[name="password-confirmation"]', form).val(),
zip: $('input[name=zip]', form).val()
};
var requestData = {
"user": {
"password": formData.password,
"role": "participant",
"email": formData.email
},
"answers": [
{
"questionId": 1,
"answer": {
"textValue": formData.firstName
}
},
{
"questionId": 2,
"answer": {
"textValue": formData.lastName
}
},
{
"questionId":3,
"answer": {
"textValue": formData.zip
}
},
{
"questionId": 4,
"answer": {
"yearValue": formData.dob
}
}
],
"signatures": [1],
"language": "en"
};
e.preventDefault();
if (formData.password === formData.passwordConfirmation) {
$.ajax({
type: "POST",
contentType: "application/json",
url: "https://app-5154.on-aptible.com/api/v1.0/profiles", // Staging Development API.
data: JSON.stringify(requestData) // please make sure to handle errors ( I've taken out our handlers since I figured you would like to write your own.)
});
} else {
$('.sign-up-form').append("<p id='password-error'>Your passwords must match.</p>");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment