We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5498
    • 9 Posts
    Hello all,

    I am having trouble with my first form using multiple submits. Once again, I have simply removed the db query and broken it down into a "debugging" script. The text generated is the one by the default statement in the switch

    First the html (called by chunk to the snippet)
    <form name="exhibitor-search" method="POST" action="exhibitor-search.php">
    
    	<fieldset>
    	
    		<legend>Search by Company name</legend>
    		<ul>
    			<li><label for="Company name">Company name : </label><input type="text" id="cName" name="cName" /><input type="submit" name="exhibitorSearch" value="Search by Company" class="input" /><input type="submit" value="Reset" id="reset" class="input" /></li>
    		</ul>
    		<legend>Search by State/Province</legend>
    		<ul>
    			<li><label for="State">State/Province : </label><input type="text" id="cState" name="cState" /><input type="submit" name="exhibitorSearch" value="Search by State" class="input" /><input type="submit" value="Reset" id="reset" class="input" /></li>
    		</ul>
    	<legend>Search by Booth No.</legend>
    		<ul>
    			<li><label for="State">Booth No. : </label><input type="text" id="cBooth" name="cBooth" /><input type="submit" name="exhibitorSearch" value="Search by Booth" class="input" /><input type="submit" value="Reset" id="reset" class="input" /></li>
    		</ul>
    	</fieldset>
    
    </form>


    Then the php inside the snippet

    <?php
    if (!isset($_POST['exhibitorSearch']) ) {
    	//show form
    		//get form chunk
    		$chunk = "ExhibitorSearchForm";
    		$esForm = $modx->getChunk($chunk);
    		echo $esForm;
    		}
     else {  
     switch ($_POST['exhibitorSearch']) {
    	case 'Search By Company' :
    		$cName = $_POST['cName'];
    		$field = "Company";
    		echo $cName;		
    		break;
    	case 'Search By State' :
    		$cName = $_POST['cState'];
    		$field = "State";
    		echo $cName;	
    		break;
    	case 'Search By Booth' :
    		$cName = $_POST['cBooth'];
    		$field = "Booth";
    		echo $cName;
    		break;		
    	default :
    	echo "broken somewhere in switch";
    		} 
    }	
    ?>


    Thanks much for any help you can offer.
      • 10487 MODX Staff
      • 1,535 Posts
      Okay, I’m guessing the problem is that your switch statement is defaulting to the ’broken ...’ statement whenever you postback.

      Remember that the switch/case is case-sensitive, so all the ’By’ words in need to be ’by’, for example: ’Search By Booth’ needs to be ’Search by Booth’

      Hope that helps,
      Garry
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 27376
        • 576 Posts
        Why not just use one "Submit" button and then have your script search by the first value that’s not empty?
        <?php
        if ($_POST['cName'] != '') {
        	// Search by Company Name
        
        } elseif ($_POST['cState'] != '') {
        	// Search by State/Province
        
        } elseif ($_POST['cBooth'] != '') {
        	// Search by Booth Number
        
        } else {
        	return 'No Information Entered.';
        }
          • 5498
          • 9 Posts
          Thank you garryn and sirlancelot for your replies!

          garryn, you were right, the search worked just fine after correcting the cases, after combing over it for two hours, hard to believe I did not catch that, so thank you for pointing it out.

          I ended up going with sirlancelot solution, and the reason is this: I need for all three buttons to be clickable, this is based on the technical "savvyness" of our users - along with an explanation, they need more of a ’graphical’ indicator. the if/elseif solution allows me to show all buttons, and the user to click any one of them, or enter text into any field and simply press Enter/Return. I had obviously not thought of that solution before.

          Thanks much!