با سلام.من توی php مبتدی هستم و میخواستم برای تمیرن یه کد بنویسم به این ترتیب که از کاربر یه عدد بگیره!(طول هستش)
بعد کاربر واحد عدد وارد شده رو از یه باکس radio انتخاب کنه که سانتی متره یا متر!
بعد خروجی موردنیازش رو از یه چک باکس انتخاب کنه که به فوت میخواد یا اینچ!(میتونه هر دو گزینه رو تیک بزنه!)
پس چی شد؟سانتی متر یا متر بگیره و به اینچ یا فوت تبدیل کنه!اینو نوشتم اما مدام ارور میده درضمن یکمی هم اشکال html ی , css ی ههم داره!
باا تشکر
کد:
<html>
<head>
<style>
.input (
color="blue";
font-family: Times New Roman;)
.result(
color="red";
font-family: Nazanin;)
.center(
text-align: center;)
.error(
color="red";
font-size="40";
)
</style>
<title>change the length parametre</title>
</head>
<body>
<?php
$value = $value2 = $input_type = "";
// erorha
//$errvalue=$errchkIT=$errchkR="";
// motaghayyer gavab
if($_SERVER["REQUEST_METHOD"]=="POST"){
test_input($_POST["value"]);
// test_input ($value2);
if($_POST["input_type"] && $_POST["$result"])
{
// shart barresi mikoneh ke fild ha por bashan
///////////////////////////////////
if($_POST["input_type"]== "cm"){ $ram=$_POST["value"]/100;
$result_inch=($ram*100)/2.54;
$result_foot=($result_inch/12);
}
/////////////////////////////////
if($_POST["input_type"]=="m"){
$ram=$_POST["value"];
$result_inch=($ram*100)/2.54;
$result_foot=($result_inch/12);
}
// ta inga gavab ha ro darim ye fekri be hale namesh bayad bokonim
// in cod ha hengam namayesh gavab bayad toye <?php dige shoru beshe
if(Ischecked ($_POST["result"],$_POST["inch"])) {
echo "<span class='result'>the value in inches is ====". $result_inch ."</span> " ;
//toye khat bala baad echo va baad " ha miavan az tag haye html estefade kard
}
if(Ischecked ($_POST["result"],$_POST["foot"])) {
echo "<span class='result'>the value in foots is ====". $result_foot ."</span>" ;
}
}
else { echo "<span class='error'>you must select one options of both tow radio forms</span>";}
}
// in kod ha hamrah php asli estefadeh mishe!
function IsChecked($chkname,$value)
{
if(!empty($chkname))
{
foreach($chkname as $chkval)
{
if($chkval == $value)
{
return true;
}
}
}
return false;
}
function test_input($data){
if(empty($data)){
echo "<span class='error'>you must insert numbers</span>" ;
break;
}else
if (preg_match("/[^0-9\.]/", $data))
{
echo "<span class='error'> Invalid Characters!</span>";
}
else {return $data;}
}
?>
<span class="center">
<h2>please enter the inputs and choose you input type!</h2>
<span class="result">only numbers are allowed</span>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELFE"]); ?>"
the value:<input type="text" name="value" >
<--! this is a test of closing tag of html by new way -->
the valu2: <input type="text" name="value2" />
type of input:
<input type="radio" name="input_type" value="cm" />Canti metre <br />
<input type="radio" name="input_type" value="m" />Metre <br />
<input type="checkbox" name="result" value="inch" />I want result in INCHs <br />
<input type="checkbox" name="result" value="foot" />I want result in FOOTs <br />
<input type="submit" />
</span>
</body>
</html>