如何让用户选择一个计划,并在下一页(表单)中动态创建


How to get a User to select a plan and be dynamically created in the next page (form)

我希望用户选择一个计划,所选择的信息动态应用到下一页,并存储在我可以通过电子邮件发送用户信息的地方。

<div class="pricing_box">
  <h3><a href="#">PROFESSIONAL</a></h3>
  <div class="price-value">
    <a href="#">$300.00/month</a>
  </div>
  <ul>
    <li><a href="#">Lorem ipsum</a></li>
    <li><a href="#">Dolor sitamet, Consect</a></li>
    <li><a href="#">Adipiscing elit</a></li>
    <li><a href="#">Proin commodo turips</a></li>
    <li><a href="#">Laws pulvinarvel</a></li>
    <li><a href="tables.html">More Details</a></li>
  </ul>
  <div class="cart">
    <a class="popup-with-zoom-anim" href="contact.html">Buy now</a>
  </div>
</div><!--pricing_box-->

<form id="myForm" action="process.php" method="POST">
<label for="humans" class="humans">Human check: Leave this field empty</label>
<input type="text" name="humans" id="humans" class="humans" />
<h1 class="intro">Professional Edition - Sign Up Today</h1>
<div class="form_style_wrapper">
<label>*Name:</label>
<input type="text" name="full_name" class="contact_first_name" title="please enter you Full 
Name" />
</div><!--end of form_style_wrapper-->
<div class="form_style_wrapper">
<label>*Email:</label>
<input type="email" name="email" class="contact_email" title="Please specify your email" /> 
</div><!--end of form_style_wrapper-->
<div class="form_style_wrapper">
<label>*Phone:</label>
<input type="tel" name="phone" class="contact_telephone" title="Please enter you mobile or telephone number" />
</div><!--end of form_style_wrapper-->
<div class="form_style_wrapper">
<label>*Company:</label>
<input type="text" name="company" class="contact_company" title="Please enter you Companies Name" />
</div><!--end of form_style_wrapper-->
<div class="form_style_wrapper">
<label for="comments">Comments:</label>
<textarea name="comments" class="contact-info" id="message"></textarea>
</div><!--end of form_style_wrapper-->
<button name="send" class="send" type="submit">Send</button> 
</form>

我有三个其他的选择,专业,基本,标准等(同一框)我可以创建一个页面并动态存储用户的选择,而不是制作额外的3个页面(表单)吗?如果选择专业,那么专业的形式(标题出现-相同的形式为所有),可以在PHP中我仍然会捕获选定的字段,所以我可以电子邮件与用户当前的选择?

你的问题不太清楚,所以我将尝试回答。如果你不想创建3个页面,你可以使用$_GET来改变页面的内容。

例如,您可以这样做

if ( isset($_GET['plan']) ) //check if the plan page is set
{
    if ($_GET['plan'] == "pro") {
        //Display Professional page here
    } elseif ($_GET['plan'] == "basic") {
        //Display Basic page here
    } elseif ($_GET['plan'] == "standard") {
        //Display Standard page here
    } else {
        echo 'The selected plan is invalid.'; //Display error message or whatever
    }
}
else
{
    //Display initial page here
}

URL应该是http://yourwebsite.com/index.php?plan=pro

一种方法是将GET变量传递给第二页。一个GET变量像这样通过url传递:

http://yoursite.com/page.php?myVar=3

所以如果用户通过点击链接选择了一个计划,这样做:

<a href="page.php?plan=1">First plan</a>
<a href="page.php?plan=2">Second plan</a>

然后,在第二页,要检索该值,使用$_GET['plan']。例如

<?php
switch($_GET['plan']){
    case "1": $title="First plan";
              break;
    case "2": $title="Second plan";
              break;
    //In case the value is not given, or incorrect
    default: print "Error, no plan selected";
             exit();
}
?>
<FORM blablabla
    ...
 <h1 class="intro"><?=$title?></h1>
    ...
</FORM>

这种方式可以将数字与计划关联起来,并使用关联的数据填充表单。