-5

我想要一个简单的 if 条件来搜索多个输入(普通文本输入)并从下拉类别框中。我需要设置一个条件,即搜索将在什么基础上进行。我需要一次从两个输入中搜索一个输入。如果两者都给出,我需要让其中一个优先于另一个。

    <form role="search" method="get" id="searchform"             
     action="http://www.sitename.com/" >

        <label class="screen-reader-text" for="s"></label>
        <input type="text" value="" name="s" id="s" align="right"/>

        <label for="category">Select Your Category</label>
        <input class="selectcategorydropdown" type="hidden" id="category"  />

<select name="s" id="category" onchange="getSelectedValue();"> 
    <option value="">none</option> 
    <option value="Kodak Gallery">Kodak Gallery</option>  
    <option value="Ritzpix">Ritxpix</option>  
    <option value="PhotoShelter">PhotoShelter</option> 
    <option value="ScanDigital">ScanDigital</option> 
</select>  

    <input type="submit" id="searchsubmit" value="Search" align="right"/>           
        </form>

我有两个输入。

我想我必须做类似的事情:


    <?php
      if (!empty($_POST['search'])) { //if there is something in search_text
         if (empty($_POST['searchform']))  {
              //search by text
          } else {
              //combined text and category search
          }
      } else  { //if there is nothing in search_text
          if (!empty($_POST['category']))  {
              // search by category
          }  else  {
              // error - no data in either $_POST['search'] or $_POST['category']
          }
      } 
?>

我做对了吗?

4

1 回答 1

0
<?php

   // Check if form was submitted
   if(!isset($_POST['search'])
   {
      // Display the form
   }
   else
   {
      // Form was submitted, check if values are empty
      if(trim($_POST['category1'])=="" )
      {
         // One or more value is empty, do something
      }

      else if (trim($_POST['category2'])=="")
      {
         // Process form
      }
   }

?>
于 2013-09-10T08:30:25.527 回答