Saving data from a drop down |
I created a menu page where it has a drop down menu with a list of menus from the database and it also has a textbox to enter new menus.
The problem I'm having is that I can't seem to figure out how to save my dropdown. So for example I have a menu called "About Us" in the drop down list and I want to create a new menu called "Team", and "Team" is a child of "About Us" So in my table I would have something like this Quote:id | parent | title Menu Controller Code: function create() create.php view Code: <div class="row"> If there is any other information you need me to give please let me know
What do you mean by how to save your dropdown?
Do you mean how to assign a menu item to a parent? If so, here is what I would do: - add a dropdown in the menu item creation form - populate said dropdown with all existing menu items, ids as values, names as...well, names When inserting check POST data if this dropdown has a chosen value, if yes, set this value to the parent column.
Website: http://tomaz.lovrec.eu
GitHub: https://github.com/slax0rr Twitter: https://twitter.com/slax0rr
I add this
Code: function get_data_from_post() to my controller, which should check the items. When I tried to save a menu item with a parent I got this error Quote:Error Number: 1452 The error Code: INSERT INTO `webkrunc_menus` (`title`, `parent`) VALUES ('Contact', 0) should look something like this Code: INSERT INTO `webkrunc_menus` (`title`, `parent`) VALUES ('Contact', 5)
Well, you are not sending in the value 5 in the POST data then. But you are sending 0. You have to watch out, that when you send 0, you don't add it to the query.
Website: http://tomaz.lovrec.eu
GitHub: https://github.com/slax0rr Twitter: https://twitter.com/slax0rr
|
Welcome Guest, Not a member yet? Register Sign In |