PHP表单标签难度

时间:2014-07-09 15:26:28

标签: php

我想生成一个用PHP和CSS编写的应用程序表单,我的问题是:在标签中,我设置了一个提交按钮,在将我的名字写入文本栏后,我得到了句子& #34;我输入的名字是:"在我的网页的左上角。我不希望在我的页面顶部显示这句话。我希望这句话低于我输入我姓名的文本框。将句子显示在我的网页顶部意味着设计糟糕的网页,但我不知道如何使这个句子出现在我希望它出现的位置。好的,当我在我的程序中删除所有其他代码(即CSS代码等)并且只有标记全部(连同句子"我输入的名称是:") ,我输入名称Gavin,我得到的是"我输入的名字是:Gavin",这句话出现在文本框的上方。这个职位似乎是默认的,没有什么可以做的。我对吗?是否有任何方法可以重新定位我的句子,使其显示在文本框下方。另外,一旦我输入了我的名字并点击了SUBMIT,有没有办法让我的文本框消失?

<?php
//brownuniversity.php
if (!empty($_POST['name'])) {
    echo "Hello, {$_POST["name"]}, and welcome.";
}
?>

<html>
<head>
  <title>Image</title>
<style>
p.pos_fixed {
  position: fixed;
  top: 30px;
  right: 50px;
  color: black;
}
h4 {
  text-decoration: underline;
}
</style>
</head>
<body>
<h4>Application Form</h4>
<img src="alphacentauri.jpg" alt="starcluster" width="200" height="200" /><br/><br/>
<p class="pos_fixed">
  <b>Brown University:</b>
  <br><br><br>
  <b>Department of Physics:</b>
</p>
<ul>
  <li>question1</li>
  <li>question2</li>
</ul>

The name that I have entered is:

<form action="brownuniversity.php" method="post">
  If you want to take part in this star-gazing project, enter your name:
  <input type="text"  name="name">
  <input type="submit">
</form>

2 个答案:

答案 0 :(得分:1)

  

在我网页的左上角

因为那是你放的地方。看看:

...

if(!empty($_POST['name'])) {
    echo "Hello, {$_POST["name"]}, and welcome.";
}
echo <<<_END
<html>

...

您在HTML开始之前输出句子。所以当然它会......在HTML之前。

如果您希望它位于页面的特定位置,请在该位置输出。例如:

...

<?php
if(!empty($_POST['name'])) {
?>
    The name that I have entered is: <?php echo $_POST["name"]; ?>
<?php
}
?>

<form action="brownuniversity.php"  method="post">

...

答案 1 :(得分:-1)

对于初学者,整理代码。

这很有希望。

<?php
//brownuniversity.php
if (!empty($_POST['name'])) {
    echo "Hello, {$_POST["name"]}, and welcome.";
}
?>

<html>
<head>
  <title>Image</title>
<style>
p.pos_fixed {
  position: fixed;
  top: 30px;
  right: 50px;
  color: black;
}
h4 {
  text-decoration: underline;
}
</style>
</head>
<body>
<h4>Application Form</h4>
<img src="alphacentauri.jpg" alt="starcluster" width="200" height="200" /><br/><br/>
<p class="pos_fixed">
  <b>Brown University:</b>
  <br><br><br>
  <b>Department of Physics:</b>
</p>
<ul>
  <li>question1</li>
  <li>question2</li>
</ul>

The name that I have entered is:
<?php
//brownuniversity.php
if (isset($_POST['name'])) {
    $_POST["name"];
}
?>

<form action="brownuniversity.php" method="post">
  If you want to take part in this star-gazing project, enter your name:
  <input type="text"  name="name">
  <input type="submit">
</form>
相关问题