正在使用模态形式更新 SQL
Updating SQL using Modal Form
我正在制作一个模态表单,它会在单击按钮时弹出并打开一个输入字段。
在保存时,它将值推送到它弹出的网页 URL。
我正在尝试捕获该值并更新数据库。
这一切都很好。
但我想刷新页面,因为 URL 仍然保留模态形式的值。
<div id="custom-modal" class="modal-demo">
<button type="button" class="close" onclick="Custombox.close()"><span>×</span><span class="sr-only">Close</span></button>
<h4 class="custom-modal-title">Add New Category</h4>
<div class="custom-modal-text text-left">
<form role="form">
<div class="form-group" method="post">
<label for="name">Category Name</label>
<input type="text" class="form-control" id="cat_name" name="cat_name" placeholder="Enter category name">
</div>
<button type="submit" class="btn btn-default waves-effect waves-light" name="btn-savecat" id="btn-savecat">Save</button>
<button type="button" class="btn btn-danger waves-effect waves-light m-l-10">Cancel</button>
<?php
if(isset($_GET['cat_name']))
{
try
{
$id=$_GET['cat_name'];
$result = $DB_con->prepare("INSERT INTO category(cat_name,cat_status)
VALUES(:userid,'Active')");
$result->bindParam(':userid', $id);
$result->execute();
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
?>
</form>
</div>
我想你应该可以用新的 HTML5 来做到这一点。有一个选项可以在不重新加载页面的情况下重写 url。但是,出于安全原因,您不能更改域名。查找历史记录 api。
我认为它会像下面这样:
history.replaceState("object or string", "title", "/another-new-url");
我正在制作一个模态表单,它会在单击按钮时弹出并打开一个输入字段。 在保存时,它将值推送到它弹出的网页 URL。 我正在尝试捕获该值并更新数据库。 这一切都很好。 但我想刷新页面,因为 URL 仍然保留模态形式的值。
<div id="custom-modal" class="modal-demo">
<button type="button" class="close" onclick="Custombox.close()"><span>×</span><span class="sr-only">Close</span></button>
<h4 class="custom-modal-title">Add New Category</h4>
<div class="custom-modal-text text-left">
<form role="form">
<div class="form-group" method="post">
<label for="name">Category Name</label>
<input type="text" class="form-control" id="cat_name" name="cat_name" placeholder="Enter category name">
</div>
<button type="submit" class="btn btn-default waves-effect waves-light" name="btn-savecat" id="btn-savecat">Save</button>
<button type="button" class="btn btn-danger waves-effect waves-light m-l-10">Cancel</button>
<?php
if(isset($_GET['cat_name']))
{
try
{
$id=$_GET['cat_name'];
$result = $DB_con->prepare("INSERT INTO category(cat_name,cat_status)
VALUES(:userid,'Active')");
$result->bindParam(':userid', $id);
$result->execute();
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
?>
</form>
</div>
我想你应该可以用新的 HTML5 来做到这一点。有一个选项可以在不重新加载页面的情况下重写 url。但是,出于安全原因,您不能更改域名。查找历史记录 api。 我认为它会像下面这样:
history.replaceState("object or string", "title", "/another-new-url");