2013-02-05 36 views
0

我有下面的代碼。這是一種使用戶能夠上傳文件的表單。我已經包含了複選框,如果用戶上傳的文件與上面列出的文件相對應,應該勾選該複選框。然後,我要檢查,如果被上傳的文件具有對應於從列表中選擇的複選框的文件名:如何檢查複選框是否被選中,如果上傳的文件具有特定的文件名

<!--SCRIPT 2 ensures that text fields are not left blank on Project form--> 
    <!--SCRIPT 2 START--> 
    <script type="text/javascript"> 
     function validateproject() 
     { 
      valid = true; 
      if (document.input.bhu_no.value == "") 
       { 
       alert ("Please enter a BHU #") 
       valid = false; 
       } 
      else if (document.input.projectname.value == "") 
       { 
       alert ("Please enter a Project Name") 
       valid = false; 
       }  
      else if (document.input.projectlead.value == "") 
       { 
       alert ("Please enter a the Project Lead Name") 
       valid = false; 
       } 
      else if (document.input.projectgoal.value == "") 
       { 
       alert ("Please enter a Project Goal Description") 
       valid = false; 
       } 
      else if (document.input.projectstartdate.value == "") 
       { 
       alert ("Please enter a Project Start Date") 
       valid = false; 
       } 
      else if (document.input.projectenddate.value == "") 
       { 
       alert ("Please enter a Project End Date") 
       valid = false; 
       } 
      /*else if (document.input.brd.value == "BRD") 
       { 
       alert ("Please upload a BRD with BRD in the title") 
       valid = false; 
       } */ 
      else if(document.getElementById("uploaded").value == "") 
       { 
       alert ("Please attach a file to be uploaded") 
       valid = false; 
       }      
      return valid; 
     } 
    </script> 
    <!--SCRIPT 2 END--> 
    <head> 
<body id="wrapper"> 
    <script type='text/JavaScript' src='calendarwidget.js'></script> 
<!--//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
                PROJECT FORM START 
    \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 
-->   
      <center><a href="#" class="show_hide"><input style="font-size:16px;" type="button" value="Rules for Uploading Files" /></a></center> 
      <div class="slidingDiv"> 
       <ul> 
        <li type="1"> 
         Creation of folders manually without filling out upload forms should not be done 
        </li> 
        <br /> 
        <li type="1"> 
         File names should be descriptive and give information about what is contained within the file 
        </li> 
        <br /> 
        <li type="1"> 
         Files uploaded must be in either Read or Read/Write property otherwise others will not be able to view the files 
        </li> 
        <br /> 
        <li type="1"> 
         Fill out text fields on upload forms fully and to the best of your knowledge 
        </li> 
        <br /> 
        <li type="1"> 
         Try and have the most recent document on the server at all times. If you want to keep many versions of a document on the server the 
         file name must end with underscore ‘_’ , capital ‘V’ and the version number (e.g. ‘KB How-to_V4.key’). 
        </li> 
        <br /> 
        <li type="1"> 
         At the end of a project upload all files related to the project onto the Knowledge Base 
        </li> 
        <br /> 
        <li type="1"> 
         Documents uploaded to the server can not be edited, if you wish to edit a document contact the uploader of the document 
        </li> 
        <br /> 
        <li type="1"> 
         When you have completed mass uploading files to the server ensure you ‘Eject’ the server 
        </li> 
       </ul> 
      </div> 




      <div id="selectproject">  
      <br /> 
      <br />  
       <form name="input" action="uploadproject.php" enctype="multipart/form-data" method="post" onsubmit="return validateproject();"> 
        <table class="bordered"> 
         <tr> 
          <th> 
           BHU # 
          </th> 
          <td> 
           <input class="uploadform" type="text" name="bhu_no" maxlength="4" size="4"/> 
           <a style='font-size:12px;' href="https://biweb3.corp.apple.com/compliance/index.php/concept/search" target="_blank"><i>Search for BHU #</i></a> 
          </td> 
         </tr> 
         <tr>  
          <th> 
           Project Name 
          </th> 
          <td> 
           <input class="uploadform" size="50" type="text" name="projectname" onkeyup="valid(this)" onblur="valid(this)" /> 
          </td> 
         </tr> 
         <tr>  
          <th> 
           Project Lead 
          </th> 
          <td> 
           <input class="uploadform" size="18" type="text" name="projectlead"/> 
          </td> 
         </tr> 
          <tr>  
          <th> 
           Project Wiki 
          </th> 
          <td> 
           <input class="uploadform" size="50" type="text" name="projectwiki"/> 
          </td> 
         </tr> 
         <tr> 
          <th> 
           BPR Track 
          </th> 
          <td> 
           <select name="bprtrack"> 
            <option value=""> 
             --BLANK-- 
            </option> 
            <option value="Manufacturing"> 
             Manufacturing 
            </option> 
            <option value="Logistics"> 
             Logistics 
            </option> 
            <option value="Supply Chain"> 
             Supply Chain 
            </option> 
            <option value="AOS"> 
             AOS          
            </option> 
            <option value="Supply/Demand Management"> 
             Supply/Demand Management           
            </option> 
            <option value="Procurement"> 
             Procurement          
            </option> 
            <option value="BI"> 
             BI          
            </option> 
            <option value="Emerging Markets"> 
             Emerging Markets 
            </option>         
           </select> 
          </td> 
         </tr> 
         <tr>  
          <th> 
           Project Goal 
          </th> 
          <td> 
           <textarea class="uploadform" rows="7" cols="50" name="projectgoal"></textarea> 
          </td> 
         </tr> 
         <tr>  
          <th> 
           Date Start 
          </th> 
          <td> 
           <INPUT TYPE='text' class="uploadform" id="projectstartdate" name="projectstartdate" SIZE='12' maxlength="10" /> 
           <img src='Images/scw.gif' title='Click Here' alt='Click Here' onclick="scwShow(scwID('projectstartdate'),event);" /> 
          </td> 
         </tr> 
         <tr>  
          <th> 
           Date End 
          </th> 
          <td> 
           <input type="text" class="uploadform" id="projectenddate" name="projectenddate" SIZE='12' maxlength="10" /> 
           <img src='Images/scw.gif' title='Click Here' alt='Click Here' onclick="scwShow(scwID('projectenddate'),event);" /> 
          </td> 
         </tr> 
         <tr>  
          <th> 
           Process(es) Effected<br /> 
           <i style='font-size:12px;'>(User Inputted, not required)</i> 
          </th> 
          <td> 
          <div class='container'> 
           <?php 

            $Results = mysql_query("SELECT processname FROM Knowledge.Process"); 

            while($Loadingrow = mysql_fetch_array($Results)) 
            {    
            echo "<input type='checkbox' value='$Loadingrow[processname]*' name='processname[]'>"; 
            echo $Loadingrow['processname']; 
            echo "<br />"; 
            }; 
           ?> 
           </div> 
          </td> 
         </tr> 
         <tr> 
          <th>Files Uploaded</th> 
          <td> 
           <input class="uploadform" type="checkbox" name="brd" value="BRD"/>BRD<br /> 
           <input class="uploadform" type="checkbox" name="playback" value="playback"/>Playback Doc.<br /> 
           <input class="uploadform" type="checkbox" name="function" value="function"/>Functional Spec.<br /> 
           <input class="uploadform" type="checkbox" name="work" value="work"/>Work Instruction<br /> 
           <input class="uploadform" type="checkbox" name="processf" value="processf"/>Process Flow<br /> 
          </td> 
          </tr>       
          <tr>  
          <th> 
           Upload File 
          </th> 
          <td> 
           <input type="file" name="uploaded" /> 
          </td> 
         </tr> 
       </table> 
       <br /> 
       <input style='font-size:2em;' type="submit" value="Upload All" name="upload"/> 
     </form> 
     </div> 
</body> 

我想知道如何檢查複選框「BRD」被選中,如果正在上傳的文件具有特定的名稱。如果文件名是正確的,則應該完成上載,否則應該拋出錯誤消息。 我不知道如何檢查頁面發佈前的複選框,也不知道如何檢查正在上傳的文件的文件名... 有人可以請指導我在正確的方向?

謝謝!

回答

0

要檢查複選框是在Javascript中檢查,你需要這樣做。

if(document.input.projectstatus.checked == true) { 

    // CODE GOES HERE 

} 

假設projectstatus是一個複選框名稱。

然後要檢查上傳的文件是否有特定名稱,請嘗試此操作。

<?php 

    if($_FILES["file"]["name"] == "specificname") { 

      // CODE GOES HERE 

    } 

?> 

假設file是窗體中的字段名稱。

+0

感謝這個!該勾選複選框工作正常,但檢查文件名的代碼根本無法工作......代碼提供的JavaScript工作? – user1958313

0

在你的JS你寫

document.getElementById("uploaded") 

,而在你的HTML你有

<input type="file" name="uploaded" /> 

請加ID = 「上傳」

+0

嗨,我已經添加了這個if語句並添加了id到html,但它仍然無效:else if(document.input.brd.checked == true && document.getElementById(「uploadedtest」)。值== 「測試」) \t \t \t \t \t { \t \t \t \t \t警報( 「請在標題上傳BRD與BRD」) \t \t \t \t \t有效= FALSE; \t \t \t \t \t} – user1958313

相關問題