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;
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>" ;
   }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.