title: Contact Form Backend needed, Frontend given
body: <p>I used to host a website at carrd.co with the pro plus plan. I chose the expensive plan because of the possibility to download the website and host it on an own server.</p>
  
  <p>What I did not know, was that this did not include server-side code.</p>
  
  <p>My problem is, that I have the front end code, but every PHP code I try fails to interact with this code. Since I can only develop with Java, I cannot get to a solution by myself.</p>
  
  <p>The issue is that I do not know what the next step is to make this code work on my server so that it successfully sends me an email when this form is submitted by a user. I do not have any backend code and do not know where to start.</p>
  
  <p>1) where can i put a PHP file to answer to this request? How do i have to name it? </p>
  
  <p>2) how can i parse the arguments? </p>
  
  <p>3) how do i have to format the answer from the php script to the ajax script? </p>
  
  <p>Could you guys please help here? Thanks a lot!!! </p>
  
  <p>(i might even be able to solve this with some good hints if you cannot be bothered to provide a full solution! I'm thankful for any advice!)</p>
  
  <p>The frontend code:</p>
  
  <p>Form:</p>
  
  <pre><code>&lt;form id="form02" method="post"&gt;
                          &lt;div class="inner"&gt;
                              &lt;div class="field"&gt;&lt;input type="text"       name="name" id="name" placeholder="Name"
                                                        maxlength="128"/&gt;&lt;/div&gt;
                              &lt;div class="field"&gt;&lt;input type="email" name="email" id="email"
                                                        placeholder="Email" maxlength="128"/&gt;&lt;/div&gt;
                              &lt;div class="field"&gt;&lt;input type="text" name="fname" id="-fname" placeholder="Fname"
                                                        maxlength="128"/&gt;&lt;/div&gt;
                              &lt;div class="field"&gt;&lt;textarea name="message" id="message" placeholder="Message"
                                                           maxlength="16384"&gt;&lt;/textarea&gt;&lt;/div&gt;
                              &lt;div class="actions"&gt;
                                  &lt;button type="submit"&gt;Send Message&lt;/button&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;input type="hidden" name="id" value="form02"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Script:</p>
  
  <pre><code>function form(id, settings) {
  var _this = this;
  this.id = id;
  this.mode = settings.mode;
  this.method = settings.method;
  this.success = settings.success;
  this.preHandler = ('preHandler' in settings ? settings.preHandler : null);
  this.failure = ('failure' in settings ? settings.failure : null);
  this.optional = ('optional' in settings ? settings.optional : []);
  this.$form = $('#' + this.id);
  this.$form.addEventListener('submit', function (event) {
      _this.submit(event);
  });
  this.$form.addEventListener('keydown', function (event) {
      if (event.keyCode == 13 &amp;&amp; event.ctrlKey) {
          event.preventDefault();
          event.stopPropagation();
          _this.submit(event);
      }
  });
  var x = $('#' + this.id + ' input[name="' + settings.hid + '"]');
  if (x) {
      x.disabled = true;
      x.parentNode.style.display = 'none';
  }
  this.$submit = $('#' + this.id + ' button[type="submit"]');
  this.$submit.disabled = false;
  };form.prototype.notify = function (type, message) {
  if (message.match(/^(#[a-zA-Z0-9\_\-]+|[a-z0-9\-\.]+:[a-zA-Z0-  9\~\!\@\#$\%\&amp;\-\_\+\=\;\,\.\?\/\:]+)$/)) location.href = message; else alert((type == 'failure' ? 'Error: ' : '') + message);
  }; 
  
  form.prototype.submit = function (event) {
  var _this = this, result, handler, fd, k, x, $f, $ff;
  event.preventDefault();
  if (this.$submit.disabled) return;
  result = true;
  $ff = this.$form.elements;
  for (k in $ff) {
      $f = $ff[k];
      if ($f.type != 'text' &amp;&amp; $f.type != 'email' &amp;&amp; $f.type != 'textarea' &amp;&amp; $f.type != 'select-one') continue;
      if ($f.disabled) continue;
      if ($f.value === '' || $f.value === null) {
          if (this.optional.indexOf($f.name) !== -1) continue;
          result = false;
      } else {
          x = '';
          switch ($f.type) {
              case 'email':
                  x = "^([a-zA-Z0-9\\_\\-\\.\\+]+)@([a-zA-Z0-9\\-     \\.]+)\\.([a-zA-Z]+)$";
                  break;
              case 'select':
                  x = "^[a-zA-Z0-9\\-]$";
                  break;
              default:
              case 'text':
              case 'textarea':
                  x = "^[^\\&lt;\\&gt;]+$";
                  break;
          }
          result = result &amp;&amp; $f.value.match(new RegExp(x));
      }
      if (!result) break;
  }
  if (!result) {
      this.notify('failure', 'Missing and/or invalid fields. Please try again.');
      return;
  }
  if (_this.method == 'get') {
      _this.$form.submit();
      return;
  }
  if (x = $(':focus')) x.blur();
  this.$submit.disabled = true;
  this.$submit.classList.add('waiting');
  handler = function (values) {
      var x, k, data;
      data = new FormData(_this.$form);
      if (values) for (k in values) data.append(k, values[k]);
      x = new XMLHttpRequest();
      x.open('POST', ['', 'post', _this.mode].join('/'));
      x.send(data);
      x.onreadystatechange = function () {
          var result = false, message = 'Sorry, something went wrong. Please try again later.', alert = true, o;
          if (x.readyState != 4) return;
          if (x.status == 200) {
              o = JSON.parse(x.responseText);
              if (o) {
                  if ('result' in o) result = (o.result === true);
                  if (('message' in o) &amp;&amp; o.message) message = o.message;
                  if ('alert' in o) alert = (o.alert === true);
              }
          }
          _this.$submit.classList.remove('waiting');
          if (result) {
              _this.$form.reset();
              if (alert) window.alert(message); else _this.notify('success', (_this.success ? _this.success : message));
          } else {
              if (alert) window.alert(message); else _this.notify('failure', (_this.failure ? _this.failure : message));
          }
          _this.$submit.disabled = false;
      };
  };
  if (_this.preHandler) (_this.preHandler)(_this, handler); else (handler)();
  };
  new form('form02', {mode: 'contact', method: 'post', hid: 'fname', success: '#contact-done',});
  </code></pre>