如何在不更改页面的情况下获取表单的输出

时间:2018-11-03 15:00:18

标签: php html

我正在尝试从textarea获取信息,以将其转换为.py文件。 这是我的文件https://jsfiddle.net/girlwhocancode/68mb49gq/

<form action=action.php method="post">
   <center>
     <textarea placeholder="Code you want to execute in python..."></textarea> 
   </center><br/>
   <center><input type="submit" class="button_example"></center>
</form>

这是我的php文件:

<?php
 $path = #PATH;
 if (isset($_POST['field1'])) {
    $fh = fopen($path,"a+");
    $string = $_POST['field1'];
    fwrite($fh,$string); // Write information to the file
    fclose($fh); // Close the file
 }
?>

由于某种原因,我的php无法正常工作,并且我不知道提交后如何保留相同的网页

1 个答案:

答案 0 :(得分:0)

尝试一下:

var ms = end - start;
var dur = ms / (1000*60*60*24);
var startDate = new Date(start);
var endDate = new Date(end);

console.log("dur = " + dur);
console.log("start = " + startDate);
console.log("end = " + endDate);

在php

<form action="action.php" method="post">
   <center>
     <textarea name="script" placeholder="Code you want to execute in python..."></textarea> //added name
   </center><br/>
   <center><input name="submit" type="submit" class="button_example"></center>
</form> // added name submit
  

请记住,在php中,$ _POST / $ _ GET键始终是您的表单字段   名称