确保自动引用PHP表单上的逻辑测试正确识别用于提交表单的HTML按钮的最佳方法是什么,当该表单实际通过jquery.submit()-rather而不是单击提交时按钮本身?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> Total Tutor </title>
<link type="text/css" rel="stylesheet" href="course.css">
<script src="../jquery.js"></script>
</head>
<body>
<script>
$(document).ready(function() {
//event that triggers the javascript/jquery form submission
$('li').dblclick(function()
{
selectedCourse=$(this).text();
sessionStorage.removeItem('selectedCourse');
sessionStorage.setItem('selectedCourse', selectedCourse);
editForm();
});
//the function called by the normal button submission and the alternative jQuery only submission: note the non jQuery one sets the $-POST variable fine
function editForm() {
var s= confirm( 'Would you like to edit ' +selectedCourse+ '');
if(s)
{
alert('form is called');
}
}
$('#edit-button').click(function() { editForm(); });
});
</script>
<?php
if(!isset($_POST['submit']))
{
?>
<ul>
<li>Maths</li>
<li>English</li>
</ul>
<form id="edit_delete" method="POST" action=" <?php echo $_SERVER['PHP_SELF']; ?>">
<button type="submit" id="edit-button" name="submit" value="edit" ><img src="../images/pencil.png"></button>
<button type="submit" id="delete-button" name="submit" value="delete" ><img src="../images/deleteo.png"></button>
</form>
}
<?php
else
{
if($_POST['submit']=='edit')
{
?>
<p>Thank you for selecting edit</p>
<?php
}
if($_POST['submit']=='delete')
{
?>
<p>Thank you for selecting delete</p>
<?php
}
}
?>
</body>
</html>
答案 0 :(得分:1)
使用变量来指示数据的发布方式。
以html格式:
getCommentsForArticle :: Slug -> App (Cmts [Comment])
getCommentsForArticle slug = do
comments <- E.select $
E.from $ \cmts -> do
let subQuery =
E.from $ \arts -> do
E.where_ $ arts ^. ArticleSlug ==. E.val slug
return (arts ^. ArticleId)
E.where_ $ cmts ^. CommentArticleId ==. E.sub_select subQuery
return cmts
return $ Cmts comments
在你的jQuery中:
<input type="hidden" name="wasClicked" id="wasClicked" value="1" />
然后在您的PHP中,测试$('#wasClicked').val("0");
以查看它是$_POST['wasClicked']
还是0