如何让我的表单输出全部显示在同一行而不是分开显示?
How do I have my out put for my form show up all together on the same line instead of spaced apart?
我需要像下面的示例那样生成我的表单,而不是完全间隔 EX。嗨 _______,你是怎么做到的 ______?
希望你玩得开心_____________。请帮忙!我是编程新手!
<html>
<head>
<title>Test1-1</title>
</head>
<body>
<?php
if (filter_has_var(INPUT_POST, "userName")){
// the form exists, so work with it
$userName = filter_input(INPUT_POST, "userName");
print "<h2>Hi $userName</h2>";
}
if(filter_has_var(INPUT_POST, "morning")){
filter_input(INPUT_POST, "morning");
print"<h2>how are you doing this morning?</h2>";
}
if(filter_has_var(INPUT_POST, "afternoon")){
print"<h2>how are you doing this afternoon?</h2>";
filter_input(INPUT_GET, "afternoon");
}
if(filter_has_var(INPUT_POST, "evening")){
print"<h2>how are you doing this evening?</h2>";
filter_input(INPUT_POST, "evening");
}
if(filter_has_var(INPUT_POST, "plan")){
$plan = filter_input(INPUT_POST, "plan");
print "<h2>Hope you have a wonderful time $plan</h2>";
}
//there's no input. Create the form
print <<< HERE
<form action ="" method = "post">
<fieldset>
<label>Please enter your name</label>
<input type = "text"
name = "userName"/><br>
<label>Time of Day</label>
<input type = "checkbox"
name = "morning"/>
<label>Morning</label>
<input type = "checkbox"
name = "afternoon"/>
<label>Afternoon</label>
<input type = "checkbox"
name = "evening"/>
<label>Evening</label><br>
<label>What are your plans?</label>
<input type = "text"
name = "plan"/><br>
<button type = "submit">
submit
</button>
</fieldset>
</form>
HERE;
// end 'value exists' if
?>
</body>
</html>
一个解决方案是用 <span>
和 </span>
替换 <h2>
和 </h2>
标签。这将根据您的需要放置它们。
<html>
<head>
<title>Test1-1</title>
</head>
<body>
<?php
echo '<p>';
if (filter_has_var(INPUT_POST, "userName")){
// the form exists, so work with it
$userName = filter_input(INPUT_POST, "userName");
print "Hi $userName";
}
if(filter_has_var(INPUT_POST, "morning")){
filter_input(INPUT_POST, "morning");
print"how are you doing this morning?";
}
if(filter_has_var(INPUT_POST, "afternoon")){
print"how are you doing this afternoon?";
filter_input(INPUT_GET, "afternoon");
}
if(filter_has_var(INPUT_POST, "evening")){
print"how are you doing this evening?";
filter_input(INPUT_POST, "evening");
}
if(filter_has_var(INPUT_POST, "plan")){
$plan = filter_input(INPUT_POST, "plan");
print "Hope you have a wonderful time $plan";
}
echo '</p>';
//there's no input. Create the form
print <<< HERE
<form action ="" method = "post">
<fieldset>
<label>Please enter your name</label>
<input type = "text"
name = "userName"/><br>
<label>Time of Day</label>
<input type = "checkbox"
name = "morning"/>
<label>Morning</label>
<input type = "checkbox"
name = "afternoon"/>
<label>Afternoon</label>
<input type = "checkbox"
name = "evening"/>
<label>Evening</label><br>
<label>What are your plans?</label>
<input type = "text"
name = "plan"/><br>
<button type = "submit">
submit
</button>
</fieldset>
</form>
HERE;
// end 'value exists' if
?>
</body>
</html>
不同部分显示在不同行的原因是您将它们包含在 <h2>
标签中。
HTML 标题元素(例如 <h2>
)是 block-level 元素。 Here is a link 到一些文档以更好地解释这到底意味着什么,但简而言之(从链接文档中引用):
Browsers typically display the block-level element with a newline both before and after the element.
为了避免这种情况,您可以简单地删除 <h2>
标签,或者用 inline element 替换它们,例如 <span>
.
我需要像下面的示例那样生成我的表单,而不是完全间隔 EX。嗨 _______,你是怎么做到的 ______? 希望你玩得开心_____________。请帮忙!我是编程新手!
<html>
<head>
<title>Test1-1</title>
</head>
<body>
<?php
if (filter_has_var(INPUT_POST, "userName")){
// the form exists, so work with it
$userName = filter_input(INPUT_POST, "userName");
print "<h2>Hi $userName</h2>";
}
if(filter_has_var(INPUT_POST, "morning")){
filter_input(INPUT_POST, "morning");
print"<h2>how are you doing this morning?</h2>";
}
if(filter_has_var(INPUT_POST, "afternoon")){
print"<h2>how are you doing this afternoon?</h2>";
filter_input(INPUT_GET, "afternoon");
}
if(filter_has_var(INPUT_POST, "evening")){
print"<h2>how are you doing this evening?</h2>";
filter_input(INPUT_POST, "evening");
}
if(filter_has_var(INPUT_POST, "plan")){
$plan = filter_input(INPUT_POST, "plan");
print "<h2>Hope you have a wonderful time $plan</h2>";
}
//there's no input. Create the form
print <<< HERE
<form action ="" method = "post">
<fieldset>
<label>Please enter your name</label>
<input type = "text"
name = "userName"/><br>
<label>Time of Day</label>
<input type = "checkbox"
name = "morning"/>
<label>Morning</label>
<input type = "checkbox"
name = "afternoon"/>
<label>Afternoon</label>
<input type = "checkbox"
name = "evening"/>
<label>Evening</label><br>
<label>What are your plans?</label>
<input type = "text"
name = "plan"/><br>
<button type = "submit">
submit
</button>
</fieldset>
</form>
HERE;
// end 'value exists' if
?>
</body>
</html>
一个解决方案是用 <span>
和 </span>
替换 <h2>
和 </h2>
标签。这将根据您的需要放置它们。
<html>
<head>
<title>Test1-1</title>
</head>
<body>
<?php
echo '<p>';
if (filter_has_var(INPUT_POST, "userName")){
// the form exists, so work with it
$userName = filter_input(INPUT_POST, "userName");
print "Hi $userName";
}
if(filter_has_var(INPUT_POST, "morning")){
filter_input(INPUT_POST, "morning");
print"how are you doing this morning?";
}
if(filter_has_var(INPUT_POST, "afternoon")){
print"how are you doing this afternoon?";
filter_input(INPUT_GET, "afternoon");
}
if(filter_has_var(INPUT_POST, "evening")){
print"how are you doing this evening?";
filter_input(INPUT_POST, "evening");
}
if(filter_has_var(INPUT_POST, "plan")){
$plan = filter_input(INPUT_POST, "plan");
print "Hope you have a wonderful time $plan";
}
echo '</p>';
//there's no input. Create the form
print <<< HERE
<form action ="" method = "post">
<fieldset>
<label>Please enter your name</label>
<input type = "text"
name = "userName"/><br>
<label>Time of Day</label>
<input type = "checkbox"
name = "morning"/>
<label>Morning</label>
<input type = "checkbox"
name = "afternoon"/>
<label>Afternoon</label>
<input type = "checkbox"
name = "evening"/>
<label>Evening</label><br>
<label>What are your plans?</label>
<input type = "text"
name = "plan"/><br>
<button type = "submit">
submit
</button>
</fieldset>
</form>
HERE;
// end 'value exists' if
?>
</body>
</html>
不同部分显示在不同行的原因是您将它们包含在 <h2>
标签中。
HTML 标题元素(例如 <h2>
)是 block-level 元素。 Here is a link 到一些文档以更好地解释这到底意味着什么,但简而言之(从链接文档中引用):
Browsers typically display the block-level element with a newline both before and after the element.
为了避免这种情况,您可以简单地删除 <h2>
标签,或者用 inline element 替换它们,例如 <span>
.