【发布时间】:2023-03-15 18:40:02
【问题描述】:
我正在使用 PHP 和 ALPCA (jquery,ajax) 构建一个表单。我在提交文件和停留在同一页面时遇到问题。我已经尝试了使用 AJAX event.preventDefault(); 的推荐技术,也使用隐藏框架但没有成功。我的问题是 ALPACA 包需要不同的方法吗?
表格部分
<script type="text/javascript">
$(document).ready(function() {
$("#form").alpaca({
"schema": {
"title":"User Feedback",
"description":"What do you think about this Speaker?",
"type":"object",
"properties": {
"email": {
"type":"string",
"title":"Email",
"required":false
},
"feedback": {
"type":"string",
"title":"Feedback"
},
"ranking": {
"type":"string",
"title":"Ranking",
"enum":['It is Great', 'Not so cool', 'Very poor quality', 'I think there may be a Privacy or Copyright issue'],
"required":false
}
}
},
"options": {
"form":{
"attributes":{
"action":"FORM.php",
"method":"post"
"target":"hiddenFrame"
},
"buttons":{
"submit":{}
}
},
"helper": "What do you think about this Speaker?",
"fields": {
"email": {
"size": 20,
"placeholder": "email not nessasary"
},
"feedback" : {
"type": "textarea",
"name": "your_feedback",
"rows": 4,
"cols": 40,
"helper": ""
},
"ranking": {
"type": "select",
"helper": "",
"optionLabels": ["It is Great", "Not so cool", "Very poor quality", "I think there may be a Privacy or Copyright issue"]
}
}
},
e.preventDefault();
});
});
</script>
PHP 文件
<?php
$file = "people.txt";
$feedback = $_REQUEST['feedback'];
$ranking = $_REQUEST['ranking'];
$email= $_REQUEST['email'];
$string = file_get_contents("/tmp/live-info");
$json = str_replace('***(', $callback, $string);
$json = rtrim($json, ')');
$json_a = json_decode($json, true);
$current_name = $json_a['current'][name];
$current_name .= "|$email|$ranking";
$feedback .= "|$current_name" .PHP_EOL;
file_put_contents($file, $feedback, FILE_APPEND | LOCK_EX);
?>
谢谢
【问题讨论】:
标签: javascript php jquery ajax forms