Im currently trying to make an application in php that gets user input from a input-box that converts units that is chosen by a dropdown box to multiple checkboxes. (example I put 2 in the input box and select inches from the dropdown box, then check cm, yard, and foot check boxes. It will display the measurements from inches to cm, yard, and feet.) Im currently stuck getting the arrays to input and am stuck on what to do.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<lable><input type="" name="Unit1" id="Unit1"></lable>
<!-- dropdown -->
<select name="Unit1" id="Unit1">
<option value="meter">meter</option>
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="km">km</option>
<option value="inch">inch</option>
<option value="yard">yard</option>
<option value="foot">foot</option>
<option value="mile">mile</option>
</select>
-->
<!-- checkbox -->
<input type="checkbox" id="meter" name="meter" value="meter">Meter<label>
<input type="checkbox" id="mm" name="mm" value="mm">mm</label>
<input type="checkbox" id="cm" name="cm" value="cm">cm</label>
<input type="checkbox" id="km" name="km" value="km">km</label>
<input type="checkbox" id="inch" name="inch" value="inch">inch</label>
<input type="checkbox" id="yard" name="yard" value="yard">yard</label>
<input type="checkbox" id="foot" name="foot" value="foot">oot</label>
<input type="checkbox" id="mile" name="mile" value="mile">mile</label>
<p></p>
<!-- Unit 2 -->
<lable><input type="" name="Unit2" id="Unit2"></lable>
<!-- dropdown -->
<select name="Unit2" id="Unit2">
<option value="liter">liter</option>
<option value="oz">oz</option>
<option value="gallon">gallon</option>
<option value="quart">quart</option>
<option value="pint">pint</option>
<option value="tab_spoon">tab_spoon</option>
<option value="tea_spoon">tea_spoon</option>
<option value="cup">cup</option>
</select>
-->
<!-- checkbox -->
<input type="checkbox" id="liter" name="liter" value="liter"><label for="liter"> liter</label>
<input type="checkbox" id="oz" name="oz" value="oz"><label for="oz"> oz</label>
<input type="checkbox" id="gallon" name="gallon" value="gallon"><label for="gallon"> gallon</label>
<input type="checkbox" id="quart" name="quart" value="quart"><label for="quart"> quart</label>
<input type="checkbox" id="pint" name="pint" value="pint"><label for="pint"> pint</label>
<input type="checkbox" id="tab_spoon" name="tab_spoon" value="tab_spoon"><label for="tab_spoon"> tab spoon</label>
<input type="checkbox" id="tea_spoon" name="tea_spoon" value="tea_spoon"><label for="tea_spoon"> tea spoon</label>
<input type="checkbox" id="cup" name="cup" value="cup"><label for="cup"> cup</label>
<p></p>
<!-- button -->
<button type="submit">Convert</button>
</form>
<?php
var_dump($_REQUEST);
// $measurement = (int)$_REQUEST["Unit1"];
?>
</body>
</html>
The beginning of your form is missing the form tag.
<form>
You also need to give the inputs a separate names so you can differentiate them in your array. Currently you are using the same name for the value and the type. Use something like Unit1_value and Unit1_name to differentiate between the two
<lable><input type="" name="Unit1_value" id="Unit1_value"></lable>
<!-- dropdown -->
<select name="Unit1_name" id="Unit1_name">
You can name the element from yourform
in array like here Html/PHP - Form - Input as array so you can differentiate each of the conversion that you want easily
you might also find this helpful How to get multiple selected values of select box in php?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.