表单提交()不提交

时间:2015-03-06 19:33:32

标签: javascript php post form-submit array-multisort

我有一个php isset if语句和用于提交的javascript,似乎并不想正确提交。我试过了:

document.getElementByID("form1").submit();
document.form1.submit();
document.forms[form1].submit();

使用this.value尝试使用和不使用变量声明的所有这些变体。

下面的代码包含javascript,而且似乎'要提交(页面刷新,'选择'选项默认返回选项0,但似乎没有提交表单数据,并且数组未正确排序。我非常php和js的新手(刚开始本周)所以我提前道歉:)

该文档还包含<html><head>代码,以及obstart()sessionstart()代码(如果有帮助)。

<script>
function submitform() 
  {
  document.getElementByID("form1").submit();
  }
</script>
# array_multisort

$sort = array();
foreach($columbs as $k=>$v) 
{
  $sort['2'][$k] = $v['2'];
  $sort['1'][$k] = $v['1'];
  $sort['4'][$k] = $v['4'];
  $sort['3'][$k] = $v['3'];
  $sort['5'][$k] = $v['5'];
  $sort['6'][$k] = $v['6'];
  $sort['7'][$k] = $v['7'];
  $sort['8'][$k] = $v['8'];
}

# sort by event_type desc and then title asc

if(isset($_POST['formSubmit']))
{
$sortbysubmit = $_POST['myselect'];
switch($sortbysubmit)
  {
  case "0": $sortby0 = array_multisort($sort['0'], SORT_ASC, $columbs); break;
  case "B1": $sortby1 = array_multisort($sort['1'], SORT_ASC, $columbs); break;
  case "B2": $sortby2 = array_multisort($sort['2'], SORT_ASC, $columbs); break;
  default: $sortby0 = array_multisort($sort['0'], SORT_ASC, $columbs); break;
  echo 'hello';
  break;
  }
}
else
  {
  array_multisort($sort['0'], SORT_ASC, $columbs);
  }
  ?>

<!--form1-->        

<form method="post" action="" id="form1" name="form1">
  <label for="form1">1</label><br>
  <select name="myselect" 2="myselect" onchange="submitform()">
    <option value="0">0</option>
    <option value="B1">1</option>
    <option value="B2">2</option>
  </select>
  <noscript>
    <input type="submit" value="Click me" />
  </noscript>
</form>

3 个答案:

答案 0 :(得分:4)

您正在检查帖子中的表单提交密钥,但您永远不会发送它。试试这个:

<form method="post" action="" id="form1" name="form1">
  <label for="form1">1</label><br>
  <select name="myselect" 2="myselect" onchange="submitform()">
    <option value="0">0</option>
    <option value="B1">1</option>
    <option value="B2">2</option>
  </select>
  <noscript>
    <input type="submit" name="formSubmit" value="Click me" />
  </noscript>
</form>

答案 1 :(得分:1)

尝试使用:

if(!empty($_POST)):

//your submission process code goes here

endif;

您似乎没有名称属性来提交按钮,因此未设置$ _POST [&#39; formSubmit&#39;]。

答案 2 :(得分:0)

我发现只是添加了

if(empty($_POST)):

$sortbysubmit = $_POST['mySelect'];

switch($sortbysubmit)
{
case "SELECT": $sortbyID = array_multisort($sort['ID'], SORT_ASC, $columbs);     break;
}

endif;

以及包括vikram的

if(!empty($_POST)):

//your submission process code goes here

endif;

似乎有效。它现在成功发布变量0以及1和2.感谢人们:))