我需要添加一个按钮来添加更多行,一次可能是10行?我还需要每个添加的行来拥有它自己的变量名吗?所以它会在下面的电子邮件模板中回响?或者它可以只是一堆字段来回应?我有一个非程序员团队将使用此表单打印出其下面的电子邮件模板,以便他们可以复制和粘贴。如果它可以有一个复制到剪贴板的按钮真的很好,但这不是主要问题。
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Remove Bad Links Template</title>
<style>
body {font-family: 'Hammersmith One', sans-serif; color:#333; }
#wrapper { width:75%; margin:0 auto; background:#f2f2f2; border:#ccc; border-radius: 10px; box-shadow:3px 3px 3px #ccc; padding:20px; }
#emailback { background: #fff; padding:20px; }
h1, h2 { color:#0074b9; }
</style>
<link href='http://fonts.googleapis.com/css?family=Hammersmith+One' rel='stylesheet' type='text/css'>
</head>
<body>
<?php
$name = $_GET['name'];
$link1 = $_GET['link1'];
$link2 = $_GET['link2'];
$link3 = $_GET['link3'];
$link4 = $_GET['link4'];
$link5 = $_GET['link5'];
$link6 = $_GET['link6'];
$link7 = $_GET['link7'];
$link5 = $_GET['link8'];
$link6 = $_GET['link9'];
$link7 = $_GET['link10'];
?>
<div id="wrapper">
<h1>Use the following template to request bad link removal</h1>
<form action="" method="GET">
<h3>WEBMASTERS NAME: <input type="text" name="name"></h3>
<h3>BAD LINK 1 <input type="text" name="link1"></h3>
<h3>BAD LINK 2 <input type="text" name="link2"></h3>
<h3>BAD LINK 3 <input type="text" name="link3"></h3>
<h3>BAD LINK 4 <input type="text" name="link4"></h3>
<h3>BAD LINK 5 <input type="text" name="link5"></h3>
<h3>BAD LINK 6 <input type="text" name="link6"></h3>
<h3>BAD LINK 7 <input type="text" name="link7"></h3>
<h3>BAD LINK 8 <input type="text" name="link8"></h3>
<h3>BAD LINK 9 <input type="text" name="link9"></h3>
<h3>BAD LINK 10 <input type="text" name="link10"></h3>
<input type="submit">
</form>
<p>
<h2>THEN COPY AND PASTE THE FOLLOWING AFTER SUBMITTING THE ABOVE FORM: </h2>
<div id="emailback">
Hi <?php echo $name; ?>, </p>
<p>
We have recently received a notification from Google stating that our website has unnatural links pointing towards it. This has really damaged our rankings on Google and as a result, we're trying to clear things up. Our website url is http://********.com.
</p><p>
We noticed the following links are pointing to our website from your site:
</p><p>
<h3><?php echo $link1; ?></h3>
<h3><?php echo $link2; ?></h3>
<h3><?php echo $link3; ?></h3>
<h3><?php echo $link4; ?></h3>
<h3><?php echo $link5; ?></h3>
<h3><?php echo $link6; ?></h3>
<h3><?php echo $link7; ?></h3>
<h3><?php echo $link8; ?></h3>
<h3><?php echo $link9; ?></h3>
<h3><?php echo $link10; ?></h3>
</p><p>
I appreciate this is inconvenient and isn't a reflection on your website at all, but if you're able to remove the links, we would really appreciate it and would be very grateful.
</p><p>
I look forward to hearing from you.
</p><p>
Jerry *****
</p><p>
*********
</p>
</p>
</div>
</div>
</body>
</html>
答案 0 :(得分:0)
好吧,让我们从一些DRY工作开始吧。
<?php
$name = isset($_GET['name']) ? $_GET['name'] : 'Webmaster';
$links = $_GET['links'] ? $_GET['links'] : array_fill(0, 10, '');
if (isset($_GET['add-rows'])) {
for ($i = 0; $i < 10; $i++) {
$links[] = '';
}
}
?>
然后修改表单:
<form method="GET">
<h3>WEBMASTERS NAME: <input type="text" name="name"></h3>
<?php
for ($i = 0; $i < count($links); $i++) {
echo '<h3>BAD LINK ' . ($i + 1) . ' <input type="text" name="links[]"></h3>';
}
?>
<input name="add-rows" type="submit" value="Add Rows">
<input type="submit" value="Submit">
</form>
最后,更改链接的输出方式:
<p>
<?php
for ($i = 0; $i < count($links); $i++) {
echo '<h3>' . $links[$i] . '</h3>';
}
?>
</p>