我在代码中使用的if(isset($_POST['submit_event'])) {
语句在我在同一页面上使用JQuery时停止工作。
有谁知道为什么?
我的完整代码:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<?php if(isset($_GET['create_event'])) {
if(isset($_POST['submit_event'])) {
echo "<script>alert('Works!');</script>";
}
?>
<form method="POST">
<button type="submit" name='submit_event' class="btn btn-default btn-sm">Aanmaken</button>
</form>
</div>
<?php } ?>
这应该警告Works!但事实并非如此。当我注释掉JQuery链接时,它确实有用..
我尝试了以下内容:
/agenda?create_event=1
<form method="POST" action='agenda.php?create_event=1'>
新页面:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<?php
if(isset($_POST['submit_event'])) {
echo "<script>alert('Works!');</script>";
} ?>
<form method="POST">
<button type="submit" name='submit_event' class="btn btn-default btn-sm">Aanmaken</button>
</form>
我发现<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
是造成问题的原因。我只是不知道为什么。
完整代码:
<?php
if(isset($_POST['submit_event'])) {
echo "<script>alert('Works!');</script>";
}
?>
<form method="POST">
Evenement Naam: <input type="text" name='ev_name'><br>
Evenement Datum: <input type="date" name='ev_date'><br>
Evenement Tijd: <input type="text" name='ev_time'><br>
Evenement Informatie: <input type="text" name='ev_info'><br>
Evenement Registratie Link: <input type="text" name='ev_link'><br>
<button type="submit" name='submit_event' class="btn btn-default btn-sm">Aanmaken</button>
</form>
答案 0 :(得分:0)
if(isset($_POST['submit_event'])) {
。
if(isset($_GET['create_event'])) {
您可以这样
if(isset($_POST['submit_event'])) {
echo 'This is Post Method';
}
if(isset($_GET['create_event'])) {
echo 'This is Get Method';
}
这里有你想要的代码
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<?php if(isset($_GET['create_event']))
{
echo "<script>alert('This is Get Method');</script>";
}
if(isset($_POST['submit_event'])) {
echo "<script>alert('This is Post Method');</script>";
}
?>
<form method="POST">
<button type="submit" name='submit_event' class="btn btn-default btn-sm">Aanmaken</button>
</form>
</div>
获取方法:
只需为get
方法
yourfile.php?create_event=1
对于帖子方法:
只需使用method="post"
从邮递员或任何表单或任何提交活动中调用该页面即可获取post
方法
答案 1 :(得分:0)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<?php if(isset($_GET['create_event'])) {
if(isset($_POST['submit_event'])) {
echo "<script>alert('Works!');</script>";
}
}
?>
<form method="POST" action="test.php?create_event=1">
<button type="submit" name='submit_event' class="btn btn-default btn-sm">Aanmaken</button>
</form>
</div>