Form submit events don'work properly?


#1

Hello, i have a problem with those form submit events.
I have a form in page in a file(guestbook.php) loaded into mainview(in index.php) and it looks like this:

<form action="send-guest-mess.php" method="post" enctype="multipart/form-data" class="form-ajax-submit send-guest-mess">
            <div class="list">
              <ul>
                <li class="item-content item-input">
                  <div class="item-media">
                    <i class="icon demo-list-icon"></i>
                  </div>
                  <div class="item-inner">
                    <div class="item-title item-label">Your entry</div>
                    <div class="item-input-wrap">
                      <textarea name="mess" class="resizable" placeholder="Message" required></textarea>
                    </div>
                  </div>
                </li>
                <li>
                  <input type="submit" name="submit" class="button" value="Send">
                </li>
              </ul>
            </div>
          </form>

I want to tweak it in ajax but im having trouble getting the response back! my js:
$$(document).on('page:init', function (e, page) {
  $$('form.send-guest-mess').on('formajax:success', function (e) {
    var xhr = e.detail.xhr; // actual XHR object
    console.log(xhr);
    var data = e.detail.data; // Ajax response from action file
    console.log(data);
    $$('.send-guest-mess').hide();
  });
  app.on('formAjaxSuccess', function (formEl, data, xhr) {
  console.log(xhr.response);
  // do something with response data
});

I am able to get data back(to add the just sent comment to guestbook page) with the second method app.on, but not with the first one! It says data and xhr are undefined…

Here is my php which adds data to database correctly, but no ajax response to f7:

  session_start();
  include "DBL.php";

  $stamp = time();
  $name = "Guest";
  $mess = "";

  if(isset($_SESSION['y5username'])){
    $name = $_SESSION['y5username'];
  }
  $mess = mysqli_real_escape_string($con, $_POST['mess']);

  // POKUD JEDE PREZ FB POPRVY, ULOZ HO DO DATABAZE

  $sql = "INSERT INTO guestbook (stamp, username, mess, public, checked)
  VALUES ('$stamp','$name','$mess',1,0)";
  $result = mysqli_query($con, $sql);

?>
       <div class="card">
       <div class="card-content card-content-padding">
       <?=$mess?>
       <p class="text-align-right padding-right">
      <?=$name?>
    </p>
  </div>
</div>

Than anybody for help. I was used to make apps mostly in php in jquery mobile, and this is my first time tryin to get more use of all the javascript magic ya’ll have created :slight_smile:


#2
      session_start();
      include "DBL.php";

      $stamp = time();
      $name = "Guest";
      $mess = "";

      if(isset($_SESSION['y5username'])){
        $name = $_SESSION['y5username'];
      }
      $mess = mysqli_real_escape_string($con, $_POST['mess']);

      // POKUD JEDE PREZ FB POPRVY, ULOZ HO DO DATABAZE

      $sql = "INSERT INTO guestbook (stamp, username, mess, public, checked)
      VALUES ('$stamp','$name','$mess',1,0)";
      $result = mysqli_query($con, $sql);

    ?>
    <div class="card">
    <div class="card-content card-content-padding">
    <?=$mess?>
    <p class="text-align-right padding-right">
    <?=$name?>
    </p>
  </div>
</div>

#3

Hi, I’m happy to try to help you, but could you tell me where this .PHP is running?