无法将 PHP 表单放入表格中

发布于 2024-08-21 04:01:12 字数 3501 浏览 5 评论 0原文

我创建了一个工作正常的表单,但是当我将其放入表格中时,它总是认为该表单不完整 - 有没有办法可以将其放入表格中(这样看起来不错!)而不会出现此问题?

-----我的 HTML-----

<h2 class="green">Interested in making life easier?</h2>

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

<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");
?>

<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />

Name:  
<input type="text" name="visitor" size="25" />
<br />

Address:<input type="text" name="visitoradd" size="25" />
<br />

City:<input type="text" name="visitorcity" size="15" />
<br />

Postcode:<input type="text" name="visitorpost" size="15" />
<br />

Email:<input type="text" name="visitormail" size="25" />
<br />

Telephone Number:<input type="text" name="visitortel" size="25" />
<br />


Bookkeeping/Payroll:<select name="bp" size="1">
<option value=" Bookkeeping">Bookkeeping </option>
<option value=" Payroll ">Payroll</option>
</select>
<br />

Number of transactions: <input type="text" name="transcations" size="15" />
<br />

Number of employees:<input type="text" name="employees" size="15" />
<br />

Payroll weekly/monthly:<select name="pmw" size="1">
<option value=" Weekly">Weekly</option>
<option value=" Monthly">Monthly</option>
</select>
<br />

<br />
<INPUT TYPE="image" SRC="images/btnSubmit.png" ALT="Submit Form">
<br />
</form>

-----我的 PHP-----

<?php

$visitor = $_POST['visitor'];
$visitoradd = $_POST['visitoradd'];
$visitorcity= $_POST['visitorcity'];
$visitorpost= $_POST['visitorpost'];
$visitormail = $_POST['visitormail'];
$visitortel = $_POST['visitortel'];
$bp = $_POST['bp'];
$transcations = $_POST['transcations'];
$employees = $_POST['employees'];
$pmw = $_POST['pmw'];


if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<h2>Please enter valid e-mail.</h2>\n";
$badinput = "<h2>Click the back button to retry.</h2>\n";
echo $badinput;
die ("Thank you.");
}

if(empty($visitor) || empty($visitormail)  || empty($visitorcity) || empty($visitorpost) || empty($visitoradd)   || empty($visitortel) || empty($bp) || empty($transcations)  || empty($employees) || empty($pmw) || empty($pmw)) 
{
echo "<h2>Please fill in all fields, click the back button to retry</h2>\n";
die ("Thank you.");
}

$message = "
Name: $visitor\n
Address: $visitoradd\n
City: $visitorcity\n
Post Code: $visitorpost\n
Email: $visitormail\n
Phone Number: $visitortel\n
Bookkeeping/Payroll: $bp\n
Number of Transactions: $transcations\n
Number Of Employees: $employees\n
Payroll Weekly/Monthly: $pmw\n"
;

$subject = "Payment Details";

mail("[email protected]",$subject,$message,$visitormail);

?>

<p align="center">
<br />
Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> )
<br />

<br />
<a href="home.php">Click here to Finish</a>
</p> 

I've created a form which works fine, but when I put it in a table it always thinks the form is incomplete - is there a way I can put it in a table (so it looks nice!) without this problem?

-----My HTML------

<h2 class="green">Interested in making life easier?</h2>

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

<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");
?>

<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />

Name:  
<input type="text" name="visitor" size="25" />
<br />

Address:<input type="text" name="visitoradd" size="25" />
<br />

City:<input type="text" name="visitorcity" size="15" />
<br />

Postcode:<input type="text" name="visitorpost" size="15" />
<br />

Email:<input type="text" name="visitormail" size="25" />
<br />

Telephone Number:<input type="text" name="visitortel" size="25" />
<br />


Bookkeeping/Payroll:<select name="bp" size="1">
<option value=" Bookkeeping">Bookkeeping </option>
<option value=" Payroll ">Payroll</option>
</select>
<br />

Number of transactions: <input type="text" name="transcations" size="15" />
<br />

Number of employees:<input type="text" name="employees" size="15" />
<br />

Payroll weekly/monthly:<select name="pmw" size="1">
<option value=" Weekly">Weekly</option>
<option value=" Monthly">Monthly</option>
</select>
<br />

<br />
<INPUT TYPE="image" SRC="images/btnSubmit.png" ALT="Submit Form">
<br />
</form>

-----My PHP-----

<?php

$visitor = $_POST['visitor'];
$visitoradd = $_POST['visitoradd'];
$visitorcity= $_POST['visitorcity'];
$visitorpost= $_POST['visitorpost'];
$visitormail = $_POST['visitormail'];
$visitortel = $_POST['visitortel'];
$bp = $_POST['bp'];
$transcations = $_POST['transcations'];
$employees = $_POST['employees'];
$pmw = $_POST['pmw'];


if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<h2>Please enter valid e-mail.</h2>\n";
$badinput = "<h2>Click the back button to retry.</h2>\n";
echo $badinput;
die ("Thank you.");
}

if(empty($visitor) || empty($visitormail)  || empty($visitorcity) || empty($visitorpost) || empty($visitoradd)   || empty($visitortel) || empty($bp) || empty($transcations)  || empty($employees) || empty($pmw) || empty($pmw)) 
{
echo "<h2>Please fill in all fields, click the back button to retry</h2>\n";
die ("Thank you.");
}

$message = "
Name: $visitor\n
Address: $visitoradd\n
City: $visitorcity\n
Post Code: $visitorpost\n
Email: $visitormail\n
Phone Number: $visitortel\n
Bookkeeping/Payroll: $bp\n
Number of Transactions: $transcations\n
Number Of Employees: $employees\n
Payroll Weekly/Monthly: $pmw\n"
;

$subject = "Payment Details";

mail("[email protected]",$subject,$message,$visitormail);

?>

<p align="center">
<br />
Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> )
<br />

<br />
<a href="home.php">Click here to Finish</a>
</p> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼角的笑意。 2024-08-28 04:01:12
<h2 class="green">Interested in making life easier?</h2>
<form method="post" action="sendemail.php">
    <?php
    $ipi = getenv("REMOTE_ADDR");
    $httprefi = getenv ("HTTP_REFERER");
    $httpagenti = getenv ("HTTP_USER_AGENT");
    ?>
    <input type="hidden" name="ip" value="<?php echo $ipi ?>" />
    <input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
    <input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />
    <table>
        <tr>
            <td><label for="visitor">Name:</label></td>
            <td><input type="text" name="visitor" size="25" /></td>
        </tr>
        <tr>
            <td><label for="visitoradd">Address:</label></td>
            <td><input type="text" name="visitoradd" size="25" /></td>
        </tr>
        <tr>
            <td><label for="visitorcity">City:</label></td>
            <td><input type="text" name="visitorcity" size="15" /></td>
        </tr>
        <tr>
            <td><label for="visitorpost">Postcode:</label></td>
            <td><input type="text" name="visitorpost" size="15" /></td>
        </tr>
        <tr>
            <td><label for="visitormail">E-mail:</label></td>
            <td><input type="text" name="visitormail" size="25" /></td>
        </tr>
        <tr>
            <td><label for="visitortel">Telephone Number:</label></td>
            <td><input type="text" name="visitortel" size="25" /></td>
        </tr>
        <tr>
            <td><label for="bp">Bookkeeping/Payroll:</label></td>
            <td>
                <select name="bp" size="1">
                    <option value=" Bookkeeping">Bookkeeping </option>
                    <option value=" Payroll ">Payroll</option>
                </select>
            </td>
        </tr>
        <tr>
            <td><label for="transcations">Number of transactions:</label></td>
            <td><input type="text" name="transcations" size="15" /></td>
        </tr>
        <tr>
            <td><label for="employees">Number of employees:</label></td>
            <td><input type="text" name="employees" size="15" /></td>
        </tr>
        <tr>
            <td><label for="pmw">Payroll weekly/monthly:</label></td>
            <td>
            <select name="pmw" size="1">
                <option value=" Weekly">Weekly</option>
                <option value=" Monthly">Monthly</option>
            </select>
            </td>
        </tr>
    </table>
    <br />
    <INPUT TYPE="image" SRC="images/btnSubmit.png" ALT="Submit Form">
    <br />
</form>
<h2 class="green">Interested in making life easier?</h2>
<form method="post" action="sendemail.php">
    <?php
    $ipi = getenv("REMOTE_ADDR");
    $httprefi = getenv ("HTTP_REFERER");
    $httpagenti = getenv ("HTTP_USER_AGENT");
    ?>
    <input type="hidden" name="ip" value="<?php echo $ipi ?>" />
    <input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
    <input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />
    <table>
        <tr>
            <td><label for="visitor">Name:</label></td>
            <td><input type="text" name="visitor" size="25" /></td>
        </tr>
        <tr>
            <td><label for="visitoradd">Address:</label></td>
            <td><input type="text" name="visitoradd" size="25" /></td>
        </tr>
        <tr>
            <td><label for="visitorcity">City:</label></td>
            <td><input type="text" name="visitorcity" size="15" /></td>
        </tr>
        <tr>
            <td><label for="visitorpost">Postcode:</label></td>
            <td><input type="text" name="visitorpost" size="15" /></td>
        </tr>
        <tr>
            <td><label for="visitormail">E-mail:</label></td>
            <td><input type="text" name="visitormail" size="25" /></td>
        </tr>
        <tr>
            <td><label for="visitortel">Telephone Number:</label></td>
            <td><input type="text" name="visitortel" size="25" /></td>
        </tr>
        <tr>
            <td><label for="bp">Bookkeeping/Payroll:</label></td>
            <td>
                <select name="bp" size="1">
                    <option value=" Bookkeeping">Bookkeeping </option>
                    <option value=" Payroll ">Payroll</option>
                </select>
            </td>
        </tr>
        <tr>
            <td><label for="transcations">Number of transactions:</label></td>
            <td><input type="text" name="transcations" size="15" /></td>
        </tr>
        <tr>
            <td><label for="employees">Number of employees:</label></td>
            <td><input type="text" name="employees" size="15" /></td>
        </tr>
        <tr>
            <td><label for="pmw">Payroll weekly/monthly:</label></td>
            <td>
            <select name="pmw" size="1">
                <option value=" Weekly">Weekly</option>
                <option value=" Monthly">Monthly</option>
            </select>
            </td>
        </tr>
    </table>
    <br />
    <INPUT TYPE="image" SRC="images/btnSubmit.png" ALT="Submit Form">
    <br />
</form>
溺渁∝ 2024-08-28 04:01:12

将表单标签放置在表格之外,如下所示:

<form>
  <TABLE>
  <TR>
    <TD>Name</TD>
    <TD><input type="text" name="visitor" size="25" /></TD>
  </TR>
  <TR>
    <TD>Address</TD>
    <TD><input type="text" name="address" size="25" /></TD>
  </TR>
  </TABLE>
</form>

如果您需要指定宽度、高度等,则使用 CSS。

这是一个很棒的教程:http://www.w3schools.com/css/

Place the form tags outside of the table like so:

<form>
  <TABLE>
  <TR>
    <TD>Name</TD>
    <TD><input type="text" name="visitor" size="25" /></TD>
  </TR>
  <TR>
    <TD>Address</TD>
    <TD><input type="text" name="address" size="25" /></TD>
  </TR>
  </TABLE>
</form>

If you are needing to specify width, height, etc.. then use CSS.

Here is a great tutorial on it: http://www.w3schools.com/css/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文