how to access html element color in php

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



how to access html element color in php



My html file makes a tag: Good car with like and dislike button. So that user can select like or unlike. Also there is submit button on screen to submit response. Code in html file is as below :
Good Car
Save Feedback



Also I do have PHP file. What I want is that when user clicks submit then my php file/code records the color of my like or dislike button (i applied these in java script code part ) and save in DB.



I don't know how to access the color of like or dislike button from html in PHP. So that if like is green then it means it has been clicked and I could increment the value in DB and similar for for dislike.





1) you should post your code so we can see what have you tried. 2) why the uppercase? seems like you are yelling
– Luis felipe De jesus Munoz
Aug 10 at 20:44





<span class="tags"> Good Car <i id="b1" class="thumbsup fa fa-thumbs-up" ></i> <i name="dislike1_color" class="thumbsdown fa fa-thumbs-down"></i> </span><button type="submit" name="addfeed" class="w3-btn w3-green">Save Feedback</button>
– user3196663
Aug 10 at 20:47






php is a server-side language and cannot get elements color but you can use javascript to get the color and send that to php
– NewToJS
Aug 10 at 20:50


php


javascript


php





You could also use the PHP echo to add the elements.
– Jack Stoller
Aug 10 at 20:52


echo





@JackStoller not sure what help using echo to add elements will be to getting the color....
– NewToJS
Aug 10 at 20:54


echo




1 Answer
1



The only way i can see how you could do this with php is if you submit the color in a form.
PHP is a server-side language as a comment allready explained. Meaning that it cant directly access everything that happens on a client side to make it simple.



An idea how you could solve your problem tho is:



If a user clicks on a from a get request is submited and it appends an attribute to the url (example.com?color=green)


<form action="/action_page.php" target="_blank" method="GET">
//This is your button
<input type="submit" value="Submit">

//this is the color
<input type="hidden" name="color" value="green">
</form>



in php you can now check if the color get param is set and if it is you can get its value


<?php
var color = "";
if (isset($_GET['color']))
color = htmlspecialchars($_GET['color']);

//To check the color use always 3 = to evade type juggling
if(color === "green")
//do something
elseif(color === "red")
//do something else


?>



//make sure not to blindly handle user input tho.





1-my form has other elements as well and currently it's having method=Post. Not sure what should i do in this situation ? 2-my element is <i id="b1" class="thumbsup fa fa-thumbs-up" ></i>. now i have to access color for element with id:b1. again not sure how i can do this in php
– user3196663
Aug 10 at 21:47







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.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard