I'm making a php email sender and I'm having trouble. Part of the form is the radio input and the user needs to select one of them. I need to get the id of the element and write it into the email (eg: "Room Type: Room2").
<div id="roomsContainer"> <input type="radio" name="roomType" id="Room1" data-customInfo="some information about room"/> <label for="Room1" class="roomTypeLabel"><div class="roomDiv">Room1</div></label> <input type="radio" name="roomType" id="Room2" /> <label for="Room2" class="roomTypeLabel"><div class="roomDiv">Room2</div></label> ..... </div>
GPT provided me with this code, but it resulted in a result of "Room Type: Open". I don't know PHP myself. How can I correct the code? So the room type would show the selected input ID, or even better the selected element "data-" tag?
$roomType = $_POST['roomType']; $body .= "Room Type: $roomType\n";
The purpose of the
id
attribute is to uniquely identify the element on the client. Its main purpose is to link to a specific part of the page, reference the element using thefor
attribute of the tag, and position it using CSS and JavaScript. It is not designed to be sent to a server. You can't get it using PHP.When the form is submitted to the server, the data will be derived from the
name
andvalue
of the success control.Therefore, any data you want to send to the server should be stored in the
value
attribute.and