2013-08-20 65 views
1

我有一个网站有多种方式可以访问我们的“向我发送电子邮件以获取更多信息”表单。 在表单上,​​它有一个复选框列表,他们可以检查他们想要通过电子邮件发送更多信息。是否可以根据他们来自哪个页面来预先检查复选框?预先核对复选框

例如,他们访问我们的“产品12”页面并点击表格的链接,并且有一个复选框可以接收有关产品12的更多信息,因为他们从产品12页面。

这里是我的表单代码:

<form id="formElem" name="formElem" action="" method="post"> 
    <fieldset class="step"> 
    <legend>Personal Details</legend> 
    <p> 
     <label for="fullname">Full Name</label> 
     <input id="fullname" name="username" /> 
    </p> 
    <p> 
     <label for="company">Company Name</label> 
     <input id="company" name="company" /> 
    </p> 
    <p> 
     <label for="title">Title</label> 
     <input id="title" name="title" /> 
    </p> 
    <p> 
     <label for="phone">Phone Number</label> 
     <input id="phone" name="phone" /> 
    </p> 
    <p> 
     <label for="email">Email</label> 
     <input id="email" name="email" placeholder="[email protected]" type="email" AUTOCOMPLETE=OFF /> 
    </p> 
    </fieldset> 
    <fieldset class="step"> 
    <legend>Products I'm interested in...</legend> 
    <p> 
     <input type="checkbox" name="telematics" value="telematics">Telematics<br> 
    </p> 
    <p> 
     <input type="checkbox" name="controllers" value="controllers">Controllers<br> 
    </p> 
    <p> 
     <input type="checkbox" name="cots" value="cots">Custom-off-the-Shelf<br> 
    </p> 
    <p> 
     <input type="checkbox" name="displays" value="displays">Displays\Operator Interfaces<br> 
    </p> 
    <p> 
     <input type="checkbox" name="cordReels" value="cordreels">Cord Reels<br> 
    </p> 
    <p> 
     <input type="checkbox" name="pdm" value="pdm">Power Distribution Modules<br> 
    </p> 
    <p> 
     <input type="checkbox" name="rtc" value="rtc">Real Time Clock<br> 
    </p> 
    </fieldset> 
    <fieldset class="step"> 
    <legend>Services I'm interested in...</legend> 
    <p> 
     <input type="checkbox" name="productDev" value="productdev">Product Development<br> 
    </p> 
    <p> 
     <input type="checkbox" name="desEng" value="deseng">Design Engineering<br> 
    </p> 
    <p> 
     <input type="checkbox" name="dfx" value="dfx">DFX<br> 
    </p> 
    <p> 
     <input type="checkbox" name="transServices" value="transServices">Transition Services<br> 
    </p> 
    <p> 
     <input type="checkbox" name="stratSourcing" value="stratSourcing">Strategic Sourcing<br> 
    </p> 
    <p> 
     <input type="checkbox" name="planning" value="planning">Planning<br> 
    </p> 
    <p> 
     <input type="checkbox" name="manufacturing" value="manufacturing">Manufacturing<br> 
    </p> 
    <p> 
     <input type="checkbox" name="fullfillment" value="fullfillment">Fullfillment<br> 
    </p> 
    <p> 
     <input type="checkbox" name="prodLifecycle" value="prodLifecycle">Product Life-Cycle Management<br> 
    </p> 
    </fieldset> 
    <fieldset class="step"> 
    <legend>Confirm</legend> 
    <p>Everything in the form was correctly filled 
    if all the steps have a green checkmark icon. 
    A red checkmark icon indicates that some field 
    is missing or filled out with invalid data. 
    </p> 
    <p class="submit"> 
     <button id="registerButton" type="submit">Register</button> 
    </p> 
    </fieldset> 
</form> 

的服务器端代码将PHP。

Plz响应。

+0

你有尝试过吗?您是否使用任何种类的服务器端语言,如PHP或ASP? –

+0

这很大程度上取决于他们如何到达相关页面,以及您是否具有服务器端脚本功能。您可能会考虑PHP中的$ _SERVER ['HTTP_REFERER']',但这不能被依赖。或者,您可以将会话变量设置为查看的最后一个项目。 – BenM

+1

_“是否可以根据他们来自哪个页面来预先检查复选框?”_是。你有什么尝试?如果有什么您需要提供更多的细节和代码。 – j08691

回答

2

如果我在你的鞋子里,我会使用查询字符串变量在链接你的产品页面到表单的链接上传递你的页面的ID(或产品ID是理想的)。

即)/formPage.html?id=12

在形式页面上,给每个输入单元的唯一ID。然后使用服务器端代码或javascript,检查查询字符串中是否存在该id,如果是,请检查它是什么,并以编程方式检查您的复选框。

这很容易使用jQuery:

$( “#product12ID”)丙( “选中”,真正的); < ----这将检查具有id = product12ID的复选框

了解您正在使用的语言(ASP.NET,PHP等)会有帮助。这将有助于微调进入的方向。

+0

感谢您的回复。我将使用PHP。 – Bucthree

+1

我是一个.NET人,所以我不知道如何在PHP中做到这一点。我更新了我的答案,以显示如何使用jquery进行操作。我提到的同样的过程将为PHP工作。 –

相关问题