Get variable from dropdown list selection
-
Hi all,
My PHP knowledge is very limited and I have been trying to do this for a couple of days now so I decided that I surely need some help..
So I have a basic form listing all the categories in a dropdown list (code below). What I would like to do is this: When the user selects a category from the list and clicks submit, I want to store a variable for the selected category (ID would be fine) and then pass it to the database. I know how to insert into the db, what I dont know is how to store the category variable…
If($_POST['Submit']) { // This is where my db insert code goes... ?> <?php } else // else we didn't submit the form, so display the form { ?> <form action="" method="post"> <select> <option value=""><?php echo esc_attr(__('Select a Category')); ?></option> <?php $categories = get_categories('orderby=name&name=categorySearch'); foreach ($categories as $category) { $option = '<option value="/category/'.$category->category_nicename.'">'; $option .= $category->cat_name; $option .= '</option>'; echo $option; } ?> </select> <input type="submit" name="Submit" id="addcoursesubmit" value="Submit" /> </form> <?php } // end else no post['submit'] ?>
Any help would be greatly appreciated!
Harry
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Get variable from dropdown list selection’ is closed to new replies.