如何使用Javascript提交POST变量? [英] How do I submit a POST variable with Javascript?

查看:90
本文介绍了如何使用Javascript提交POST变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图通过一个表单提交一个变量和变量的名字。我将按钮从提交切换为按钮,因为我需要额外的验证。



无论如何,现在按钮:

 < button type =buttononclick =subForm()name =delid =deletebuttonvalue ='。org。'>删除<按钮> 

以下是我目前的验证:

 < script type =text / javascript> 
函数subForm()
{
if(confirm(你确定要删除它?))
document.forms [addorg]。submit() ;
else
返回false;

}
< / script>

以下是我的脚本:

  if(isset($ _ POST [del])&&($ _POST ['del']!=='')){
$ del = mysql_real_escape_string(html2txt($ _ POST ['del']));
$ resfile = mysql_query('从组织中选择file_loc WHERE org_id ='。$ del);
$ org_name = mysql_real_escape_string(html2txt($ _ POST ['orgname']));

if(!$ resfile)
header('Location:'。$ admin。'?error = query');

while($ filerow = mysql_fetch_array($ resfile)){
$ fileplace = $ filerow ['file_loc'];
unlink(。。$ fileplace);
rmdir($ org_name);
}

mysql_query(从组织中删除org_id ='。$ del。');
header('Location:'。$ admin);
}

它目前不删除我想要的记录。

解决方案

您可以使用< ; input type =hidden>

  echo'< input type =hidden name =org_idvalue ='。$ org_id。'/>'

应显示如下内容:

 < input type =hiddenname =org_idvalue =1/> 

使用此代码,您可以使用以下方式访问隐藏的字段数据:

  $ org_id = $ _POST ['org_id']; 


So I am trying to submit a variable and the name of the variable via a form. I switched a button from submit to button because I need additional validation.

Anyway, here's the button now:

<button type="button" onclick="subForm()" name="del" id="deletebutton" value="'.$org.'">Delete</button>

Here's my current validation:

<script type="text/javascript">
function subForm() 
{
    if(confirm("Are you sure you want to delete this?"))
        document.forms["addorg"].submit();
   else
       return false;

}
</script>

And here's my script on the other side:

if (isset($_POST["del"])  && ($_POST['del'] !== '')) {
    $del = mysql_real_escape_string(html2txt($_POST['del']));
    $resfile = mysql_query('SELECT file_loc from organization WHERE org_id = '.$del);
    $org_name = mysql_real_escape_string(html2txt($_POST['orgname']));

    if (!$resfile) 
        header('Location: '.$admin.'?error=query');

    while ($filerow = mysql_fetch_array($resfile)) {
        $fileplace = $filerow['file_loc'];
        unlink(".".$fileplace);
        rmdir($org_name);
    }

    mysql_query("DELETE from organization where org_id='".$del."'");
    header('Location: '.$admin);
}

It is not currently deleting the records that I want. How do I pass along the "del" name to the other page?

解决方案

You can use <input type="hidden">:

echo '<input type="hidden" name="org_id" value="'.$org_id.'" />'

This should render something like:

<input type="hidden" name="org_id" value="1" />

Using this code you can access the hidden field data using:

$org_id = $_POST['org_id'];

这篇关于如何使用Javascript提交POST变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆