dongou2019 2014-01-28 15:36
浏览 38
已采纳

在PHP中添加其他行

I need to add a button to add more rows, maybe 10 at a time? I also need each added row to have it's own variable name right? So it will echo out in the email template below? Or can it just be a bunch of fields to echo out? I have a team of non-programmers that will be using this form to print out the email template below it, so they can copy and paste. Would really be nice if it could have a button to copy to clipboard, but thats not the main issue.

<!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>
  • 写回答

1条回答 默认 最新

  • dongwei4444 2014-01-28 15:49
    关注

    Alright, let's start with some DRY work.

    <?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[] = '';
        }
    }
    ?>
    

    And then modify your form:

    <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>
    

    And finally, change how your links output:

    <p>
    <?php
    for ($i = 0; $i < count($links); $i++) {
        echo '<h3>' . $links[$i] . '</h3>';
    }
    ?>
    </p>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测