Hello! In general, the task is such that somewhere, I crookedly get data from the form that I can not write to the file.

There is html file

<div class="modal fade" id="sendMsgToPhp" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <form> <div class="form-group"> <label for="theme">Тема</label> <input type="text" name="theme" class="form-control" id="theme" placeholder="Тема"> </div> <div class="form-group"> <label for="time">Время</label> <input type="text" name="time" class="form-control" id="time" placeholder="Время"> </div> <button type="submit" class="btn btn-default">Отправить</button> <div class="success" style="display: none;"> <p>Добавлено!</p> </div> </form> </div> </div> </div> 

Taken with jquery

 $(document).ready(function () { $("#sendMsgToPhp").submit(function (event) { event.preventDefault(); $.ajax({ type: "POST", url: "../php_scripts/update.php", data: $("#sendMsgToPhp").serialize(), success: function () { $('.success').delay(600).fadeIn(1000); } }); }); }); 

Now we write to the file via php

 <?php $theme = $_POST['theme']; $time = $_POST['time']; $today = $theme . " " . $time; $fh = fopen("testfile.txt", 'r+') or die("Сбой открытия файла"); fseek($fh, 0, SEEK_END); fwrite($fh, $today) or die("Сбой записи в файл"); fclose($fh); ?> 
  • So what is the error-curvature? - Peresada
  • Just the data is not recorded, which I send) - ratatuy
  • Try using the $ today variable to write echo $today; // did something appear? - Peresada
  • I tried, emptiness, and shoved an empty line in my notebook (because there is nothing to accept with post'a) - ratatuy
  • one
    #sendMsgToPhp is a div. it does not have a submit event. Hang the event on the form - axmed2004

1 answer 1

 $(this).serialize() либо $('#sendMsgToPhp form').serialize() 

instead

 $("#sendMsgToPhp").serialize()