dsgdfh302506 2013-01-25 01:59
浏览 41
已采纳

为什么这会返回false?

So I have a select in a form...

<select id="aca" name="aca">
  <option value="2012">2012-2013</option>
  <option value="2011">2011-2012</option>
  <option value="2010">2010-2011</option>
  <option value="2009">2009-2010</option>
  <option value="2008">2008-2009</option>
  <option value="2007">2007-2008</option>
  <option value="2006">2006-2007</option>
  <option value="2005">2005-2006</option>
</select>

Looks good, right ? Then I want to check if the whole form is set:

if(isset($_FILES['fichier']) && isset($_POST['nom']) && isset($_POST['a']) && isset($_POST['c']) && isset($_POST['t']) && isset($_POST['auteur']) && isset($_POST['aca'])) echo 'tout';

Well this always return FALSE, and I know it's due to 'aca'. When I try...

if(isset($_POST['aca'])) echo 'aca';

It returns TRUE if I selected something in the list, and the other condition still doesn't echo 'tout', so I just see 'aca'. And this js line doesn't seem to be the problem as other select's return TRUE.

$("select").prop('selectedIndex', -1);

I really don't understand... HALP ^^"

Full HTML:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <title>Upload</title>
  <link rel="stylesheet" href="style/upload.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="js/upload.js"></script>
</head>
<body>

<form method="post" action="" enctype="multipart/form-data">

<fieldset>
<legend>Informations d'upload</legend>
<p>Fichier (tous formats | max. 1 Mo):</p>
<input type="file" name="fichier" size="60"/><br/>
<p>Nom du fichier. Caractères utilisables: alphanumériques °*@()-_()</p>
<input type="text" name="nom" size="40"/>
</fieldset>

<fieldset>
<legend>Classification</legend>
<p>Merci d'indiquer où ce fichier devra être classé.</p>
  <select id="a" name="a">
    <option value="0">BA1</option>
  </select>
  <select id="c" name="c" style="display:none"></select>
  <select id="t" name="t" style="display:none"></select>
</fieldset>

<fieldset>
<legend>Détails</legend>
<p>Auteur:</p>
<input type="text" name="auteur" size="40"/>
<p>Année académique:</p>
<select id="aca" name="aca">
  <option value="2012">2012-2013</option>
  <option value="2011">2011-2012</option>
  <option value="2010">2010-2011</option>
  <option value="2009">2009-2010</option>
  <option value="2008">2008-2009</option>
  <option value="2007">2007-2008</option>
  <option value="2006">2006-2007</option>
  <option value="2005">2005-2006</option>
</select>
</fieldset>

<br/>

<div style="width:500px;text-align:center">
<input type="submit" name="submit" value="Envoyer" />
</div>

</form>
</body>
</html>

Full PHP:

<?php
$formats = array('pdf');
echo strtolower(substr(strrchr($_FILES['fichier']['name'],'.'),1)).'<br/>';
if(isset($_POST['aca'])) echo 'aca';
if(isset($_FILES['fichier']) && isset($_POST['nom']) && isset($_POST['a']) && isset($_POST['c']) && isset($_POST['t']) && isset($_POST['auteur']) && isset($_POST['aca'])) echo 'tout';
if(preg_match("#^[a-zA-Z0-9éè°*@ ()_-]{10,50}$#",$_POST['nom']))
{
echo 'OK';
}
else echo 'Nope';
?>
  • 写回答

2条回答 默认 最新

  • douxuanpa8298 2013-01-25 02:09
    关注

    If nothing is selected, the element doesn't POST to the server. You can fix this by making the select:

    <select id="aca" name="aca">
      <option value="" selected="selected"> </option>
      <option value="2012">2012-2013</option>
      <option value="2011">2011-2012</option>
      <option value="2010">2010-2011</option>
      <option value="2009">2009-2010</option>
      <option value="2008">2008-2009</option>
      <option value="2007">2007-2008</option>
      <option value="2006">2006-2007</option>
      <option value="2005">2005-2006</option>
    </select>
    

    And again, you must do this for the other "select" elements if you want them to POST without selecting something.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥150 HDMI分路器LT86102 的输出在890MHz频点处EMC超标8DB
  • ¥36 如何安全的迁移用户C盘用户文件(戴尔电脑)
  • ¥15 druid(相关搜索:数据库|防火墙)
  • ¥15 大一python作业
  • ¥15 preLaunchTask"C/C++: aarch64- apple-darwin22-g++-14 生成活动 文件”已终止,退出代码为-1。
  • ¥60 如何鉴定微信小程序数据被篡改过
  • ¥18 关于#贝叶斯概率#的问题:这篇文章中利用em算法求出了对数似然值作为概率表参数,然后进行概率表计算,这个概率表是怎样计算的呀
  • ¥20 C#上传XML格式数据
  • ¥15 elementui上传结合oss接口断点续传,现在只差停止上传和继续上传,各大精英看下
  • ¥20 手机截图相片分辨率降低一半