Jump to content

Problems Directing To A Thank You Page


kazgrafix
 Share

Recommended Posts

Hi Everyone I'm currently amending a php event calendar script to suit my websites needs. I have managed to get it working how I want apart from one aspect which I think is relating to the Javascript. I need the script to redirect the user to a Thank you page after they have submitted their payment details. I'm thinking I may need to be putting a line of code in after line 299? Can someone have a look at the coding below and help me in the right direction?

/** * @requires JABB 0.1 */function EBCal () { var document = window.document; this.options = {};this.date = null;this.event_id = null;this.category_id = null;this.version = "0.1";this.getVersion = function () {return this.version;}; this.bindCalendar = function () {var i, len, self = this,cells = JABB.Utils.getElementsByClass(this.options.class_name_dates, document.getElementById(this.options.container_calendar), "td");//Add "click" event to calendar cellsfor (i = 0, len = cells.length; i < len; i++) {JABB.Utils.addEvent(cells[i], "click", function (event) {self.triggerLoading('message_1', self.options.container_events);if (self.options.position === 2) {document.getElementById(self.options.container_calendar).style.display = 'none';}self.loadEvents(this.getAttributeNode("axis").value);});}//Add "click" event to calendar nav linksvar a = JABB.Utils.getElementsByClass(self.options.class_name_month, document.getElementById(self.options.container_calendar), "a");for (var m, y, rel, j = 0, alen  = a.length; j < alen; j++) {JABB.Utils.addEvent(a[j], "click", function (event) {rel = this.getAttributeNode("rel").value;switch (rel.split("-")[0]) {case 'next':m = parseInt(self.options.month, 10) + parseInt(self.options.view, 10) > 12 ? parseInt(self.options.month) + parseInt(self.options.view, 10) - 12 : parseInt(self.options.month) + parseInt(self.options.view, 10);y = parseInt(self.options.month, 10) + parseInt(self.options.view, 10) > 12 ? parseInt(self.options.year) + 1 : parseInt(self.options.year);break;case 'prev':m = parseInt(self.options.month, 10) - parseInt(self.options.view, 10) < 1 ? parseInt(self.options.month) - parseInt(self.options.view, 10) + 12 : parseInt(self.options.month) - parseInt(self.options.view, 10);y = parseInt(self.options.month, 10) - parseInt(self.options.view, 10) < 1 ? parseInt(self.options.year) - 1 : parseInt(self.options.year);break;}self.triggerLoading('message_5', self.options.container_calendar);self.loadCalendar(m, y);});a[j].onclick = function (e) {return false;}} // Add 'mouseover' and 'mouseout' eventvar t = JABB.Utils.getElementsByClass('calendarEvent', document.getElementById(this.options.container_calendar), "td");for (i = 0, len = t.length; i < len; i++) {JABB.Utils.addEvent(t[i], "mouseover", function (event) {if (document.getElementById('t_' + this.getAttributeNode("id").value)) {document.getElementById('t_' + this.getAttributeNode("id").value).style.visibility = 'visible';}});JABB.Utils.addEvent(t[i], "mouseout", function (event) {if (document.getElementById('t_' + this.getAttributeNode("id").value)) {document.getElementById('t_' + this.getAttributeNode("id").value).style.visibility = 'hidden';}});}}; this.bindEvents = function () {var i, len, self = this,btn = JABB.Utils.getElementsByClass(this.options.class_name_events, document.getElementById(this.options.container_events), "input"); // Add "click" event to Book buttonfor (i = 0, len = btn.length; i < len; i++) {JABB.Utils.addEvent(btn[i], "click", function (event) {self.triggerLoading('message_2', self.options.container_events);self.loadBookingForm(this.getAttributeNode("rev").value);});}}; this.bindClose = function () {var i, len, self = this,btnClose = JABB.Utils.getElementsByClass(this.options.events_close, document.getElementById(this.options.container_events), "a");// Add "click" event to Close linkfor (i = 0, len = btnClose.length; i < len; i++) {JABB.Utils.addEvent(btnClose[i], "click", function (event) {if (event.preventDefault) {event.preventDefault();}document.getElementById(self.options.container_events).innerHTML = "";if (self.options.position === 2) {document.getElementById(self.options.container_calendar).style.display = "";}});btnClose[i].onclick = function (e) {return false;}}}; this.bindBookingForm = function () {var self = this;// Add "change" event to Payment method combo boxif (document.forms[self.options.booking_form_name] && document.forms[self.options.booking_form_name][self.options.booking_form_payment_method]) {JABB.Utils.addEvent(document.forms[self.options.booking_form_name][self.options.booking_form_payment_method], "change", function () {// if there will be any credit card option...if (self.options.cc_data_flag) {var $ccData = JABB.Utils.getElementsByClass(self.options.cc_data_wrapper, document.forms[self.options.booking_form_name], "DIV")[0],$value = this.options[this.selectedIndex].value; if ($value == 'creditcard') {// show the credit cards fields$ccData.style.display = "block"; // for each field add a requered class namefor (i = 0; i < self.options.cc_data_names.length; i++) {JABB.Utils.addClass(document.forms[self.options.booking_form_name][self.options.cc_data_names[i]], 'EBCal_Required');}} else {// hide the credit cards fields$ccData.style.display = "none"; // for each field remove the requered class namefor (i = 0; i < self.options.cc_data_names.length; i++) {JABB.Utils.removeClass(document.forms[self.options.booking_form_name][self.options.cc_data_names[i]], 'EBCal_Required');}}}});} //Add "click" event to Submit buttonif (document.forms[self.options.booking_form_name] && document.forms[self.options.booking_form_name][self.options.booking_form_submit_name]) {JABB.Utils.addEvent(document.forms[self.options.booking_form_name][self.options.booking_form_submit_name], "click", function (event) {var $this = this;$this.disabled = true;if (!self.validateBookingForm($this)) {return;}if ($this.form.captcha) {JABB.Ajax.getJSON(self.options.get_booking_captcha_url + "&captcha=" + $this.form.captcha.value, function (json) {switch (json.code) {case 100:self.errorHandler('\n' + self.options.validation.error_captcha);$this.disabled = false;break;case 200:self.loadBookingSummary(JABB.Utils.serialize(document.forms[self.options.booking_form_name]));self.triggerLoading('message_4', self.options.container_events); break;}});} else {self.loadBookingSummary(JABB.Utils.serialize(document.forms[self.options.booking_form_name]));self.triggerLoading('message_4', self.options.container_events); } });}//Add "click" event to Cancel buttonif (document.forms[self.options.booking_form_name] && document.forms[self.options.booking_form_name][self.options.booking_form_cancel_name]) {JABB.Utils.addEvent(document.forms[self.options.booking_form_name][self.options.booking_form_cancel_name], "click", function (event) {this.disabled = true;self.triggerLoading('message_1', self.options.container_events);self.loadEvents(); });}// Add "change" event to pricevar priceSelect = JABB.Utils.getElementsByClass(self.options.class_name_price, document.forms[self.options.booking_form_name], "SELECT");if (document.forms[self.options.booking_form_name]) {for (var i = 0, len = priceSelect.length; i < len; i++) {JABB.Utils.addEvent(priceSelect[i], "change", function (event) {self.loadPrices();});}}}; this.bindBookingSummary = function (post) {var self = this;//Add "click" event to Submit buttonif (document.forms[self.options.booking_summary_name] && document.forms[self.options.booking_summary_name][self.options.booking_summary_submit_name]) {JABB.Utils.addEvent(document.forms[self.options.booking_summary_name][self.options.booking_summary_submit_name], "click", function (event) {var $this = this;$this.disabled = true;if (!self.validateBookingSummary($this)) {return;}JABB.Ajax.postJSON(self.options.get_booking_save_url + "&cid=" + self.options.calendar_id, function (json) {switch (json.code) {case 100:self.errorHandler('\n' + self.options.message_8);$this.disabled = false;break;case 200:self.loadPaymentForm(json);break;} }, post + "&" + JABB.Utils.serialize(document.forms[self.options.booking_summary_name]) + "&calendar_id=" + self.options.calendar_id + "&event_id=" + self.event_id);});}//Add "click" event to Cancel buttonif (document.forms[self.options.booking_summary_name] && document.forms[self.options.booking_summary_name][self.options.booking_summary_cancel_name]) {JABB.Utils.addEvent(document.forms[self.options.booking_summary_name][self.options.booking_summary_cancel_name], "click", function (event) {this.disabled = true;self.triggerLoading('message_2', self.options.container_events);self.loadBookingForm(undefined, post, 1);});}}; this.bindCategory = function () {var self = this;if (document.forms[self.options.category_form_name] && document.forms[self.options.category_form_name].category_id) {JABB.Utils.addEvent(document.forms[self.options.category_form_name].category_id, "change", function (event) {self.category_id = this.options[this.selectedIndex].value;self.loadCalendar(self.options.month, self.options.year);});}}; this.loadCalendar = function (m, y) {var self = this,queryStr = "&cid=" + self.options.calendar_id + "&view=" + self.options.view + "&month=" + m + "&year=" + y + "&category_id=" + self.category_id;JABB.Ajax.sendRequest(self.options.get_calendar_url + queryStr, function (req) {document.getElementById(self.options.container_calendar).innerHTML = req.responseText;document.getElementById(self.options.container_events).innerHTML = "";if (self.options.position === 2) {document.getElementById(self.options.container_calendar).style.display = '';}self.options.month = m;self.options.year = y;self.bindCalendar();});}; this.loadEvents = function (date) {if (typeof date !== "undefined") {this.date = date;}var self = this,qs = "&cid=" + self.options.calendar_id + "&date=" + self.date + "&category_id=" + self.category_id;JABB.Ajax.sendRequest(this.options.get_events_url + qs, function (req) {document.getElementById(self.options.container_events).innerHTML = req.responseText;self.bindEvents();self.bindClose();});}; this.loadPrices = function () {var self = this,arr = [],price_arr = JABB.Utils.getElementsByClass(self.options.class_name_price, document.forms[self.options.booking_form_name], "SELECT");for (var i = 0, len = price_arr.length; i < len; i++) {arr.push(price_arr[i].name + "=" + encodeURIComponent(price_arr[i].options[price_arr[i].selectedIndex].value));}JABB.Ajax.get(self.options.get_price_url + "&cid=" + self.options.calendar_id + "&" + arr.join("&"), self.options.container_price);}; this.loadBookingForm = function (event_id, post, loadPrices) {if (typeof event_id !== "undefined") {this.event_id = event_id;}var self = this,qs = "&cid=" + self.options.calendar_id + "&date=" + self.date + "&event_id=" + self.event_id;JABB.Ajax.sendRequest(self.options.get_booking_form_url + qs, function (req) {document.getElementById(self.options.container_events).innerHTML = req.responseText;self.bindBookingForm();self.bindClose();if (typeof loadPrices !== "undefined") {self.loadPrices();}}, post);}; this.loadBookingSummary = function (post) {var self = this,qs = "&cid=" + self.options.calendar_id;JABB.Ajax.sendRequest(self.options.get_booking_summary_url + qs, function (req) {document.getElementById(self.options.container_events).innerHTML = req.responseText;self.bindBookingSummary(post);self.bindClose();}, post);}; this.loadPaymentForm = function (obj) {var self = this,qs = "&cid=" + self.options.calendar_id,bs, d;JABB.Ajax.sendRequest(self.options.get_payment_form_url + qs, function (req) {bs = document.forms[self.options.booking_summary_name];if (bs && bs.parentNode) {d = document.createElement("div");d.innerHTML = req.responseText;bs.parentNode.insertBefore(d, bs); if (typeof document.forms[self.options.payment[obj.payment]] != 'undefined') {document.forms[self.options.payment[obj.payment]].submit();} else {self.triggerLoading('message_7', self.options.container_events);}} }, "id=" + obj.booking_id);}; this.toggleCreditCard = function () { }; this.validateBookingForm = function (btn) {var re = /([0-9a-zA-Z\.\-\_]+)@([0-9a-zA-Z\.\-\_]+)\.([0-9a-zA-Z\.\-\_]+)/,message = ""; var frm = document.forms[this.options.booking_form_name];for (var i = 0, len = frm.elements.length; i < len; i++) {var cls = frm.elements[i].getAttributeNode("class");if (cls && cls.value.indexOf("EBCal_Required") !== -1) {switch (frm.elements[i].nodeName) {case "INPUT":switch (frm.elements[i].type) {case "checkbox":case "radio":if (!frm.elements[i].checked && frm.elements[i].getAttribute("rev")) {message += "\n - " + frm.elements[i].getAttribute("rev"); }break;default:if (frm.elements[i].value.length === 0 && frm.elements[i].getAttribute("rev")) {message += "\n - " + frm.elements[i].getAttribute("rev");}break;}break;case "TEXTAREA":if (frm.elements[i].value.length === 0 && frm.elements[i].getAttribute("rev")) { message += "\n - " + frm.elements[i].getAttribute("rev");}break;case "SELECT":switch (frm.elements[i].type) {case 'select-one':if (frm.elements[i].value.length === 0 && frm.elements[i].getAttribute("rev")) {message += "\n - " + frm.elements[i].getAttribute("rev"); }break;case 'select-multiple':var has = false;for (j = frm.elements[i].options.length - 1; j >= 0; j = j - 1) {if (frm.elements[i].options[j].selected) {has = true;break;}}if (!has && frm.elements[i].getAttribute("rev")) {message += "\n - " + frm.elements[i].getAttribute("rev");}break;}break;default:break;}}if (cls && cls.value.indexOf("EBCal_Email") !== -1) {if (frm.elements[i].nodeName === "INPUT" && frm.elements[i].value.length > 0 && frm.elements[i].value.match(re) == null) {message += "\n - " + this.options.validation.error_email;}}}var price_arr = JABB.Utils.getElementsByClass(this.options.class_name_price, document.forms[this.options.booking_form_name], "SELECT"),max = frm.event_max_people.value,cnt = 0;for (var i = 0, len = price_arr.length; i < len; i++) {cnt += parseInt(price_arr[i].options[price_arr[i].selectedIndex].value, 10);}if (cnt > max) {message += "\n - " + this.options.validation.error_max.replace(/\[max\]/, max);} else if (cnt === 0) {message += "\n - " + this.options.validation.error_min;}if (message.length === 0) {return true;} else {this.errorHandler(message); btn.disabled = false;return false;}}; this.validateBookingSummary = function (btn) {var po = document.getElementsByName("payment_option"),poLength = po.length,pass = false,message = "\n" + this.options.validation.error_payment,i; for (i = poLength - 1; i >= 0; i--) {if (po[i].checked) {pass = true;break;}} if (poLength === 0) {pass = true;} if (pass) {return true;} else {this.errorHandler(message); btn.disabled = false;return false;}}; this.errorHandler = function (message) {var err = JABB.Utils.getElementsByClass("EBCal_Error", document.forms[this.options.booking_form_name], "P");if (err[0]) {err[0].innerHTML = this.options.validation.error_title + message.replace(/\n/g, "<br />");err[0].style.display = '';} else {alert(this.options.validation.error_title + message);}}; this.triggerLoading = function (message, container) {document.getElementById(container).innerHTML = this.options[message];document.getElementById(this.options.container_messages).innerHTML = '';}; this.init = function (calObj) {this.options = calObj;this.bindCalendar();this.bindCategory();}}

I may be looking in completely the wrong place for this and it may actually be something I need to do within PHP, any advice would be greatly appreciated. Thanking you in advance Caroline.

Edited by kazgrafix
Link to comment
Share on other sites

If the loadPaymentForm function sends the ajax request and gets markup for the payment form back, and then submits the form, then you'll need to do the redirection on whatever page that form submits to. The markup for the form is coming from the server so I can't tell any more than that, I can't tell what page it is submitting to for example.

Link to comment
Share on other sites

Thanks for this, I'm thinking the coding may need to go in the PHP code below as this is where the coding to redirect to the Thank you page is for people paying via paypal and worldpay. I need it also to redirect when paying via the standard payment form. Below I have only copied the payments section of the coding within this file, can you see if this is where the coding needs to be and what I need to put in?

<?phprequire_once CONTROLLERS_PATH . 'AppController.controller.php';/** * Load payment form * * @access public * @return void */function paymentForm(){$this->isAjax = true; if ($this->isXHR()){Object::import('Model', array('Booking', 'Event'));$BookingModel = new BookingModel();$EventModel = new EventModel(); $BookingModel->addJoin($BookingModel->joins, $EventModel->getTable(), 'TE', array('TE.id' => 't1.event_id'), array('TE.event_title'));$arr = $BookingModel->get($_POST['id']); $this->tpl['arr'] = $arr;if (count($booking_arr) == 0){Util::redirect($option_arr['thank_you_page']);}} /** * Authorize.NET confirmation: Send email and redirect to "Thank you" page * * @access public * @return void */function confirmAuthorize(){$this->isAjax = true; Object::import('Model', array('Booking', 'Option', 'Event'));$BookingModel = new BookingModel();$EventModel = new EventModel();$OptionModel = new OptionModel(); $option_arr = $OptionModel->getPairs($_POST['x_custom_calendar_id']);$BookingModel->addJoin($BookingModel->joins, $EventModel->getTable(), 'TE', array('TE.id' => 't1.event_id'), array('TE.event_title'));$booking_arr = $BookingModel->get($_POST['x_invoice_num']);if (count($booking_arr) == 0){Util::redirect($option_arr['thank_you_page']);} if (intval($_POST['x_response_code']) == 1){$BookingModel->update(array('id' => $_POST['x_invoice_num'], 'booking_status' => $option_arr['payment_status']));Front::confirmSend($option_arr, $booking_arr, $this->salt, 3);}Util::redirect($option_arr['thank_you_page']);}/** * PayPal confirmation: Send email and redirect to "Thank you" page * Use as IPN too * * @access public * @return void */function confirmPaypal(){$this->isAjax = true; $url = TEST_MODE ? 'sandbox.paypal.com' : 'www.paypal.com';$log = '';Front::log("\nPayPal - " . date("Y-m-d")); Object::import('Model', array('Booking', 'Option', 'Event'));$BookingModel = new BookingModel();$EventModel = new EventModel();$OptionModel = new OptionModel(); $option_arr = $OptionModel->getPairs($_POST['custom']);$BookingModel->addJoin($BookingModel->joins, $EventModel->getTable(), 'TE', array('TE.id' => 't1.event_id'), array('TE.event_title'));$booking_arr = $BookingModel->get($_POST['invoice']);if (count($booking_arr) == 0){Front::log("No such booking");Util::redirect($option_arr['thank_you_page']);} $req = 'cmd=_notify-validate';foreach ($_POST as $key => $value){$value = urlencode(stripslashes($value));$req .= "&$key=$value";} // post back to PayPal system to validate$header  = "POST /cgi-bin/webscr HTTP/1.0\r\n";$header .= "Content-Type: application/x-www-form-urlencoded\r\n";$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";$fp = fsockopen($url, 80, $errno, $errstr, 30); // assign posted variables to local variables$invoice = $_POST['invoice'];$payment_status = $_POST['payment_status'];$payment_amount = $_POST['mc_gross'];$payment_currency = $_POST['mc_currency'];$txn_id = $_POST['txn_id'];$receiver_email = $_POST['receiver_email']; if (!$fp){// HTTP ERRORFront::log("HTTP error");} else {fputs ($fp, $header . $req);while (!feof($fp)){$res = fgets ($fp, 1024);if (strcmp ($res, "VERIFIED") == 0){Front::log("VERIFIED");if ($payment_status == "Completed"){Front::log("Completed");if ($booking_arr['txn_id'] != $txn_id){Front::log("TXN_ID is OK");if ($receiver_email == $option_arr['paypal_address']){Front::log("EMAIL address is OK");$booking_amount = $booking_arr['payment_option'] == 'deposit' ? $booking_arr['booking_deposit'] : $booking_arr['booking_total'];if ($payment_amount == $booking_amount && $payment_currency == $option_arr['currency']){Front::log("AMOUNT is OK, proceed with booking update");$BookingModel->update(array('id' => $invoice, 'booking_status' => $option_arr['payment_status'], 'txn_id' => $txn_id, 'processed_on' => array('NOW()')));Front::confirmSend($option_arr, $booking_arr, $this->salt, 3);Util::redirect($option_arr['thank_you_page']);}}}}Util::redirect($option_arr['thank_you_page']);   } elseif (strcmp ($res, "INVALID") == 0) {    Front::log("INVALID");  Util::redirect($option_arr['thank_you_page']);  }}fclose($fp);}}

Thank you for your help Caroline.

Link to comment
Share on other sites

I can't tell just by looking at the code which other pages use that code. But it looks like they have a static class that they use to redirect: Util::redirect($option_arr['thank_you_page']); You can put any URL you want in there, and maybe try it in a few places to try and figure out which parts of that code the form that you're trying to change is using. This will redirect to Google, for example: Util::redirect('http://www.google.com');

Link to comment
Share on other sites

Sorry I should have said that I set which url I want to redirect to within the admin section of the event calendar. The Paypal and the Authorize options both go to the thank you page after payment has been received without any problems. The problem is the payment form section which does not seem to be redirecting? I'm not sure if the Util:: coding is in the right place for this?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...