我有一个带单选按钮,选项框(下拉框),复选框,文本字段等的HTML表单。我的表单指向另一个名为send.php的文件,用于通过电子邮件发送表单,但是我该如何使用复选框和单选按钮并在每个答案之间输入文本呢?我想将其格式化为:
欢迎使用:{name}您的年龄段介于以下之间:{带年龄段的单选按钮}
等等。我无法提供实际的代码,因为它是私有的,但是我可以使用代码和格式的种类来代替它:
<form action="send.php">
<input type="radio" name="AgeGroup" value="AgeGroup1"> 0-18<br>
<input type="radio" name="AgeGroup" value="AgeGroup2"> 19-29<br>
<input type="radio" name="period" value="AgeGroup3"> 30-39<br>
<input type="radio" name="period" value="AgeGroup4"> 40-49<br>
<input type="radio" name="period" value="AgeGroup5"> 50+<br>
<br><br><br><br>
<select name="Country">
<option value ="UK">United Kingdom</option>
<option value ="USA">United States</option>
</option></select>
<br><br><br><br>
<input type="text" name="PostCode" size="5">
<br><br><br><br>
<input type="text" name="HouseNumber" size="5">
<br><br><br><br>
<textarea id="Family" class="input" name="FamilyNumber" rows="10" cols="60"></textarea>
<br><br><br><br>
<input type="checkbox" name="Delievery" value="NextDay"> Next Day Delievery
<br>
<input type="checkbox" name="Delievery" value="TwoToFive"> 2-5 Day
<br>
<input type="checkbox" name="Outcome" value="Dismissed"> Dismissed
<br><br><br><br><br><br>
<center><button id="Send" type="submit" style="height:25px; width:100px; background-color: grey">Send</button></center>
</form>
抱歉,太随机了。我没主意了!也对我的编码能力感到抱歉,我通常不做HTML!
谢谢。
我希望这会有所帮助...如果我正确理解了您的问题。
确保将方法添加到表单标签中。例如:<form action="send.php" method="post">
。在send.php中,您想按名称属性获取变量,例如:
$name = $_POST['Name'];
$ageGroup = $_POST['AgeGroup'];
然后,您要构建您的电子邮件。PHP允许将变量解析为双引号字符串,这可以帮助您以所需的方式构建消息。(参考)
$to = "[email protected]";
$subject = "Subject goes here";
$message = "Welcome: $name. Your age group is between: $ageGroup";
//note: headers are optional
$headers = "From: [email protected]" . "\r\n" . "CC: [email protected]";
mail($to, $subject, $message, $headers);
这只是一个简单的示例,但这也许可以帮助您入门。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句