在输入框中获取url值

时间:2012-06-07 11:27:02

标签: php javascript

在我的html页面中,我有这样的链接

<table width="100%" border="0" cellspacing="4" cellpadding="4">
          <tr>
            <td><a href="ApplicationRegister.php?plan=trial"><img src="images/box4.png" width="230" height="300" /></a></td>
            <td><a href="ApplicationRegister.php?plan=plan1"><img src="images/box1.png" width="230" height="300" /></a></td>
            <td><a href="ApplicationRegister.php?plan=plan2"><img src="images/box2.png" width="230" height="300" /></a></td>
            <td><a href="ApplicationRegister.php?plan=plan3"><img src="images/box3.png" width="230" height="300" /></a></td>
          </tr>
        </table>

当我点击任何一个图像时,它将转到带有plan =相应值的ApplicationRegister.php页面。

在我的ApplicationRegister.php中,我有一个注册表单

<form action="emailconfirmation.php" method="post" name="form1" id="form1"  onsubmit="return Validate();">
    Company Name: 
        <input type="text" name="CompanyName" style="width:230px; height:20px;" /><br /><br />
    Company E-mail : 
    <input type="text" name="Companyemail" style="width:230px; height:20px;" /><br /><br />
     Company Contact <input type="text" name="CompanyContact" style="width:230px; height:20px;" /><br /><br />
     Company Address: <input type="text" name="CompanyAddress" style="width:230px; height:20px;" /><br /><br />
     <input type="hidden" name="form_submitted" value="1"/> 
     <input type="submit" value="REGISTER" name="submit" />
                    </form>

在这个页面中,它应该从url中获取值,例如plan = trail或plan1 ......无论url是什么。然后提交所有值时,应与这些表格数据一起提交。

如何实现这一目标?请帮忙。

3 个答案:

答案 0 :(得分:5)

首先,您需要清理计划输入:

<?php
    $plan = @$_GET['plan'];
    $plan = +$plan; #convert to number
?>

只需添加另一个包含该值的隐藏字段

<form action="emailconfirmation.php" method="post" name="form1" id="form1" onsubmit="return Validate();">
    ...
    <input type="submit" value="REGISTER" name="submit" />
    <input type="hidden" name="plan" value="<?php echo $plan ?>"/> 
</form>

另一种选择是将其作为get参数添加到action

<form action="emailconfirmation.php?plan=<?php echo $plan ?>"
      method="post" name="form1" id="form1" onsubmit="return Validate();">
    ...
    <input type="submit" value="REGISTER" name="submit" />
</form>

答案 1 :(得分:0)

嘿,如果你发送一个值作为URL的一部分,那么你应该有一个容器来抓住它...使用php $ _GET []来获取该值...一些关于php表单的谷歌搜索将帮助你而不是给你代码。

http://www.w3schools.com/php/php_forms.asp请阅读此链接并继续编码!!

答案 2 :(得分:0)

您需要在ApplicationRegister.php上为表单添加一个隐藏字段,其中包含“plan”查询参数。以下HTML应位于以下格式中:

<input type="hidden" name="plan" value="<?php echo isset($_GET['plan']) ? $_GET['plan'] : 'trial'; ?>" />

如果代码访问此页面而未通过上一页,则代码会将默认值设置为“试用”。

然后您可以像往常一样在'emailconfirmation.php'中处理表单数据。你可以这样做:

 if (isset($_POST)) 
 { 
     $post_Plan = isset($_POST['plan']) ? $_POST['plan'] : null; 
     // etc ...
 } else {
     // redirect back 
 }