问题是:在更新db之前运行确认用户请求。有两种选择:点击时使用submitfunc
我可以运行js确认,获得用户选择,但在upload_db
功能中,我无法捕捉用户输入的值(它是' s textarea值)
如果我使用button type="submit...
我可以获得textarea值,但我不知道如何运行确认并在更新db之前获得确认返回值。我该如何解决这个问题?
<?php
session_start();
// In case user press button_lookfor
if (isset($_POST['button_lookfor'])) {
// I run sql select...
}
// In case user press button_update
if (isset($_POST['button_update'])) {
//to update db i have to get value of textarea.Ok in this case
$sql_upd = "UPDATE db SET field_value ='" .$_POST['alpha_9_10']."'";
}
function upload_db(){
//I am not able to catch the value entered in textarea
if (isset($_POST['alpha_9_10'])) {
//....
}
}
?>
<html>
<head>
<script language="javascript" type="text/javascript">
function submitFunc(){
var r = confirm("Press OK per confermare la modifica al database!");
if (r == true) {
var x="<?php upload_db(); ?>";
alert(x);
return false;
}
}
</script>
</head>
</style>
<body>
<form method="post" action="" >
<table class='table1' id="pos_table1" >
<tr><td><textarea name="alpha_9_10"<textarea></td></tr>
</table>
<button type="submit" name="button_lookfor" >Look for data</button>
<button type="submit name="button_update" >Save data</button>
<!--<button type="button" onClick="submitFunc();"name="button_update">Save</button>-->
</body>
</form>
</html>
答案 0 :(得分:0)
您可以尝试返回确认值(当用户点击按钮时为true或false)。只有在用户按下确定时才会提交表单。这看起来像是:
<?php
session_start();
// In case user press button_lookfor
if (isset($_POST['button_lookfor'])) {
// I run sql select...
}
// In case user press button_update
if (isset($_POST['button_update'])) {
//to update db i have to get value of textarea.Ok in this case
$sql_upd = "UPDATE db SET field_value ='" .$_POST['alpha_9_10']."'";
}
function upload_db(){
//I am not able to catch the value entered in textarea
if (isset($_POST['alpha_9_10'])) {
//....
}
}
?>
<html>
<head>
</head>
</style>
<body>
<form method="post" action="" >
<table class='table1' id="pos_table1" >
<tr><td><textarea name="alpha_9_10"<textarea></td></tr>
</table>
<button type="submit onClick="return confirm('Press OK per confermare la modifica al database!')" name="button_update" >Save data</button>
</body>
</form>
</html>