我一直在试图弄清楚单选按钮和复选框是否需要在通过电子邮件发送它们时清除(清理?)以及如何执行此操作。PHP单选按钮在电子邮件中安全
我有一个联系表单,只是通过电子邮件发送信息。它不会触及数据库。电邮时,我是否需要保护单选按钮和复选框?可能吗?
我还没有发现任何关于在通过电子邮件发送这些邮件时获得这些保护的问题。我不断遇到一些答案,说这些答案应该在发送到数据库时一定受到保护。这里也是一样,或者是关于如何获取值或动态创建值的问题。所以,我不知所措。
电子邮件时是否保护单选按钮和复选框?可能吗?必要?如果是这样,我该怎么做?
这里是我的代码是什么样子的,部分:
$firstName = strip_tags($_POST['firstName']);
$lastName = strip_tags($_POST['lastName']);
$email = strip_tags($_POST['emailAddress']);
$telNum = strip_tags($_POST['phoneNumber']);
$colors= $_POST['eColors'];
$additionalComments = strip_tags($_POST['additionalComments']);
$spamField = strip_tags($_POST['sField']);
<form id="contact-form" action="" method="post">
<div>
<input type="text" id="nameFirst" name="firstName" />
<label for="nameFirst" class="nameIcon">
<span>First Name</span>
</label>
<span class="hint">
<p>Input hint goes here</p>
</span>
</div>
<div>
<input type="text" id="nameLast" name="lastName" />
<label for="nameLast" class="nameIcon">
<span>Last Name</span>
</label>
<span class="hint">
<p>Input hint goes here</p>
</span>
</div>
<div>
<input type="email" id="eAddy" name="emailAddress" />
<label for="eAddy" class="emailIcon">
<span>Contact Email</span>
</label>
<span class="hint">
<p>Input hint goes here</p>
</span>
</div>
<div>
<input type="tel" id="telNum" name="phoneNumber" />
<label for="telNum" class="contactIcon">
<span>Contact Number</span>
</label>
<span class="hint">
<p>Input hint goes here</p>
</span>
</div>
<div>
<input type="checkbox" id="cbEColors" name="eColors" class="cbSwitch" />
<label for="cbEColors">Do you expect more color?</label>
</div>
<div>
<textarea id="addComments" name="additionalComments"></textarea>
<label for="addComments" class="messageIcon">
<span>Additional Comments</span>
</label>
<span class="hint">
<p>Input hint goes here</p>
</span>
</div>
<input type="text" id="sField" class="col" name="sField" />
<button id="submit" name="submit" type="submit" value="Submit">Submit</button>
</form>
你有没有机会知道如何确保单选按钮或复选框?我知道一般输入使用strip_tags。 IE'strip_tags($ _ POST ['phoneNumber']);'我如何为另外两个做这件事?另外,是的,这是有益的,我已经收藏了书签,所以我拥有它。谢谢。 – Jaime
答案可能会有所不同,具体取决于允许的复选框值。我个人会为字段定义可接受值的数组,并执行如下操作:$ checkboxValue =(!empty($ _ POST ['checkboxInput'])&& in_array($ _ POST ['checkboxInput'],$ acceptedValues))? $ _POST ['checkboxInput']:null; 它检查输入是否有值,以及该值是否在可接受值的数组中。如果满足这些条件,$ checkboxValue被赋值为发送的值,否则设置为null。 – flauntster
我刚刚在搜索中发现。谢谢。 – Jaime