-1

I am fine getting the value of a form controls such as radio and select for example but with all of the additional non form based controls available for Bootstrap i haven't really seen many PHP examples how to use these.

So my main question is with pure PHP how would you retrieve the current selected item from a div and li based dropdown?

http://www.bootply.com/b4NKREUPkN

or a custom color picker plugin?

http://bootstrapformhelpers.com/colorpicker/#jquery-plugins

zeddex
  • 1,260
  • 5
  • 21
  • 38
  • html 5 has a new element to add a colour picker, check you the html 5 documentation. – CodingInTheUK May 01 '15 at 13:47
  • I want to use bootstrap, this is a general question also as there could be many types of custom control based around div or li etc elements – zeddex May 01 '15 at 14:28
  • because with bootstrap the submission of the data to php is taken over by javascript. something similar to this. $('#elementid').html(); to get the contents of the element. – CodingInTheUK May 02 '15 at 01:55

1 Answers1

1

If you are submitting a form and handling the request using PHP, you will not be able to access the DOM in PHP (client vs server). If you can pull out the bits that you need using javascript, you can set the values on hidden form elements and submit.

<?php 
// print out the value when the post is submitted
if (isset($_POST["extraInput"])) {
    echo "hidden input is: " + $_POST["extraInput"];
}

?>

<html>
    <head>
        <script type="text/javascript">
            function doSubmit () {
                var extraValue = document.getElementById("extra").innerHTML;
                var form = document.forms["myForm"];
                form.elements["extraInput"].value = extraValue;
                form.submit();    
            }
        </script>
    </head>

    <div id="extra">Hello world</div>

    <body>
        <form id="myForm" action="" method="post">
            <input type="hidden" name="extraInput" />
            <input type="text" name="textInput" />
            <button onclick="javascript:doSubmit()">Submit</button>
        </form>
    </body>
</html>
Ian Morse
  • 56
  • 3
  • Is there not a pure PHP way to do it just like regular form elements? Why would bootstrap developers base new controls on the div and li elements if PHP cannot be used easily? – zeddex May 01 '15 at 15:49
  • Nope. PHP doesn't know about the DOM because it executes first. This answer gives a good overview: http://stackoverflow.com/questions/4151833/order-of-execution-in-web-environment – Ian Morse May 04 '15 at 12:53