Jump to content

How can I get the value of a switch case coming from the drop down form?


Lisa23

Recommended Posts

Hi I have a form that is popluated from the database now I am trying to get the switch case to be based on the option the user selects is this possible to make a case a variable popluated by the drop down if so can someone show me what am i missing?

the value I am trying to get from the form to the switch case is the ( $val->slug) but the value not been set help please

 

here the form

                                       <form method="post">
                                           <select name="deal-locations" onChange="this.form.submit()">
                                             <?php
                                             	while(list($key,$val) = each($locations)) {
                                             ?><option value="<?php echo $val->slug; ?>"><?php echo $val->slug; ?></option><?php
                                                 }
                                              ?>
                                           </select>
                                           <input type="submit" value="submit">
                                       </form>

 

Here the switch case

switch ($_POST['deal-locations'])
   { 
       case " $val->slug": echo "<h3>deal-locations: ASC</h3>";
           $args = array(
                 's' => $_GET['s'],
                 'post_type' => 'deals',
                 'deal-locations' => ' $val->slug',
                 'where' => ' $val->slug',
                 'paged' => 'paged'
                );
           break;
}

Sorry, but at least for me, this code made no sense...

 

<?php echo $val->slug; ?>

 

Here you want to echo the returned value of a function (without brackets) in an object you have created and assigned to the $val variable. :o

 

switch ($_POST['deal-locations'])
   { 
       case " $val->slug": echo "<h3>deal-locations: ASC</h3>";
           $args = array(
                 's' => $_GET['s'],
                 'post_type' => 'deals',
                 'deal-locations' => ' $val->slug',
                 'where' => ' $val->slug',
                 'paged' => 'paged'
                );
           break;
}

Same function call (without brackets) should equal $_POST['deal-locations']?

 

 

Sorry if there is something I don't understand about this. I'm not an expert on OOP in PHP.

HI thanks for all the help guys what I was trying to achieve was this, is working now I used the if statmenet instead.

 

    $val->slug = $_POST['deal-locations'];
   if($val->slug)
   { 
       $args = array(
             's' => $_GET['s'],
             'post_type' => 'deals',
             'deal-locations' => $val->slug,
             'where' => $val->slug,
             'paged' => 'paged');
		 echo "<h3> ".$val->slug."</h3>" ;
   }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.