jquery - Oauth 2 with php and Javascript form -


hi have form created in javascript , use oauth bearer key. have tried several attempts cannot seem figured out. please review code below , help! successful post, cannot rest work properly. not 100% sure if there need php script or if should using pure js/jquery achieve desired result.

<script>      jquery.fn.visible = function() {          return this.css('visibility', 'visible');      };        jquery.fn.hidden = function() {          return this.css('visibility', 'hidden');      };        var fadeform = (function() {          var email_regex = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i;            var fadeform = {              _filledslide: 0,              fadenext: function() {                  var self = this;                  var openslide = $('.slide.open');                  if (openslide.length) {                      var nextslide = openslide.next('.slide');                      if (nextslide.length) {                          openslide.removeclass('open');                          settimeout(function() {                              nextslide.addclass('open');                              var curslideidx = $('.slide').index(nextslide);                              $('#previous').visible();                                if (curslideidx < self._filledslide) {                                  $('#next').visible();                              } else {                                  $('#next').hidden();                                  self._filledslide = curslideidx;                              }                          }, 250);                      }                  }              },              fadeprev: function() {                  var self = this;                  var openslide = $('.slide.open');                  if (openslide.length) {                      var nextslide = openslide.prev('.slide');                      if (nextslide.length) {                          openslide.removeclass('open');                          settimeout(function() {                              nextslide.addclass('open');                              var curslideidx = $('.slide').index(nextslide);                              if (curslideidx === 0) {                                  $('#previous').hidden();                              }                              if (curslideidx < self._filledslide) {                                  $('#next').visible();                              } else {                                  $('#next').hidden();                              }                          }, 250);                      }                  }              },              validatezip: function() {                  var self = this;                  var endpoint = '/ajax.php/validatezip';                  var zip = $.trim($('#zip_validate').val());                  $.post(endpoint, {zip: zip}, function(data) {                      if (data.valid) {                          $('#zip_validate').closest('.validate_field').removeclass('error');                          $('#city').val(data.info.city);                          $('#state').val(data.info.state);                          $('#zip').val(zip);                          fadeform.fadenext();                      } else {                          $('#zip_validate').closest('.validate_field').addclass('error');;                          $('#next').hidden();                      }                  });              },              validatefields: function($slide) {                  var self = this;                  var isvalid = true;                  $slide.children('.validate_field').each(function(idx) {                      var $inp = $(this).children('.validate_input');                      if($.trim($inp.val()) === '') {                          $(this).addclass('error');                          isvalid = false;                      } else {                          $(this).removeclass('error');                      }                  });                  if(isvalid) {                      self.fadenext();                  } else {                      $('#next').hidden();                  }                  return isvalid;              },              validatecredit: function(value) {                  this.fadenext();                  return;                  if(value == 539) {                      $('.validate_field.validate-credit').addclass('error');                      $('#next').hidden();                  } else {                      $('.validate_field.validate-credit').removeclass('error');                      this.fadenext();                  }              },              validate: function() {                  return true;              }          };            return fadeform;      })();        $(function() {          $('#vaformtarget').load(function() {              window.location.href = '/veteranscalculatorthankyou.php';          });            $('#propertyvalue').slider({              range: 'min',              min: 75000,              max: 2000000,              step: 25000,              value: <?= $propertyvalue?>,              slide: function(event, ui) {                  $('#property_value').val(ui.value);                  $('#propval').html('$' + ui.value);              }          }).draggable();          $('#loanbalance').slider({              range: 'min',              min: 0,              max: 2000000,              step: 25000,              value: <?= $mortgagebalance?>,              slide: function(event, ui) {                  $('#loan_balance').val(ui.value);                  $('#loanbal').html('$' + ui.value);              }          }).draggable();            $('.slide-form-container form').keydown(function(e) {              if (e.which === 13) {                  return false;              }          });            $('#zip_validate').keydown(function(e) {              if (e.which === 13) {                  $('.continue.validate.zip').trigger('click');              }          });              $('label :radio, button.continue:not(.validate)').on('click', function() {              if($(this).hasclass('validate-credit')) {                  fadeform.validatecredit($(this).val());              } else {                  fadeform.fadenext();              }          });            $('button.validate').on('click', function() {                if ($(this).hasclass('zip')) {                    fadeform.validatezip();                } else {                    var validated = fadeform.validatefields($(this).closest('.slide'));                    if($(this).hasclass('submit') && validated) {                        var $form = $(this.form);                        $.ajax({                            type: 'post',                            url: $form.attr('action'),                            contenttype : 'application/x-www-form-urlencoded',                            data: $form.serialize(),                            headers: {                                authorization: 'bearer <?=get_auth_token()?>'                            },                            success: function(response) {                                window.location.href = '/veteranscalculatorthankyou.php';                            },                            error: function(xhr, status, error) {                                var err = eval("(" + xhr.responsetext + ")");                                console.log(err);                            }                        });                    }                }            });            $('#previous').on('click', function() {              fadeform.fadeprev();          });            $('#next').on('click', function() {              fadeform.fadenext();          });      });
<?php   //require_once "http/request.php";    function get_auth_token()  {      $service_url = 'https://wsrv.slgmortgage.com/token';      $curl = curl_init($service_url);            $curl_post_data = array(              'content-type': 'application/x-www-form-urlencoded',              'grant_type' => 'password',              'username' => 'xxxrateforvetsxxx',              'password' => 'v7zkfzkfaqmyhzt2fvkxh66edmgs5cx4uacyqbdszeaeqdzajvycrpncqgeqjtaw');      curl_setopt($curl, curlopt_returntransfer, true);      curl_setopt($curl, curlopt_post, true);      curl_setopt($curl, curlopt_postfields, $curl_post_data);      $curl_response = curl_exec($curl);      if ($curl_response === false) {          $info = curl_getinfo($curl);          curl_close($curl);          die('error occured during curl exec. additioanl info: ' . var_export($info));      }        curl_close($curl);      $decoded = json_decode($curl_response);      if (isset($decoded->response->status) && $decoded->response->status == 'error') {          die('error occured: ' . $decoded->response->errormessage);      }      //$token = $decoded->response->access_token;      //return $token;            //if (isset($decoded->error) {      //  die('error occured: ' . $decoded->error);      //}            return var_export($curl_response);  }  ?>


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -