how to store value of the li tag in php and submit into database
how to store value of the li tag in php and submit into database
I'm beginner in PHP building a e-commerce website. I have an issue with product size. I want to store the value of product size when clicked on add to cart button.
Using ul and li tag in html to show size range for front end I want to add product size into cart table.
Can I use name attribute in ul tag to store value and pass through the form?
Here is my code
<div class="col-sm-8 col-sm-12">
<div class="filter-box">
<div class="widget size">
<h6 class="widget-title">Size</h6>
<div class="widget-desc">
<div class="row">
<ul style="display: contents;">
<li id="1"><a class="filter-size-box" href="#">XS</a></li>
<li id="2"><a class="filter-size-box" href="#">S</a></li>
<li id="3"><a class="filter-size-box" href="#">M</a></li>
<li id="4"><a class="filter-size-box" href="#">L</a></li>
<li id="5"><a class="filter-size-box" href="#">XL</a></li>
<li id="6"><a value="" class="filter-size-box" href="#">XXL</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
3 Answers
3
There's no attribute like "name" for ul/li tag. You shouldn't use ul for this, you should use with
<form method="POST">
<select name="sizes">
<option value="1">XS</option>
<option value="2">S</option>
</select>
</form>
Then when you submit the form(POST) in PHP you'll have access to the values with $_POST['sizes']
$_POST['sizes']
It can be coded with JS and CSS that the select will look and behave as it was list with UL. There are already some components that are done like this and you may use them.
i know that but check this image i given my screenshot of size range imgur.com/a6HDXzO
– Shivam
Sep 5 '18 at 9:38
can u suggest me how i can do this with js and use into form
– Shivam
Sep 5 '18 at 9:42
You can add hidden input in the form in this case and then set the value of this input with the help of jquery on click on anchor link.
show me some example so i can move further with this
– Shivam
Sep 5 '18 at 9:44
1) Add hidden input inside of the form 2) Write a jquery click handler for the anchor links 3) Inside click handler, find the parent elements ID attribute 4) Put this id as a value of hidden input.
– CodeThing
Sep 5 '18 at 9:47
<input type="hidden" id="size"> where i kept this input tag below the ul tag
– Shivam
Sep 5 '18 at 9:52
<script> $("#sizelist").on("click", "a", function(e) e.preventDefault(); var $this = $(this).parent(); $this.addClass("select").siblings().removeClass("select"); $("#sizevalue").val($this.data("value")); ); </script>
– Shivam
Sep 5 '18 at 11:14
<ul style="display: contents;" id="sizelist"> <li data-value="XS" value="XS"><a class="filter-size-box" href="#">XS</a></li> <li data-value="S"><a class="filter-size-box" href="#">S</a></li> <li data-value="M"><a class="filter-size-box" href="#">M</a></li> </ul> <input id="sizevalue" name="size" type="hidden" />
– Shivam
Sep 5 '18 at 11:15
You should have to find some CSS like checkbox and make design like your need . and then you can use "name" attribute
but client want this only, so i don't how to do it help bro
– Shivam
Sep 5 '18 at 9:45
You should try something like this stackoverflow.com/questions/41816293/…
– Siddharth Ramani
Sep 5 '18 at 9:59
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
what should i do?
– Shivam
Sep 5 '18 at 9:33