表单 - 处理textarea和checkbox变量

时间:2010-07-15 21:23:09

标签: php forms variables

好吧,所以我把我的表单通过电子邮件发送给php中的大部分变量。但是,我的textarea变量显示为空白,我的textarea输入打印为“Array”

以下是我的表单摘录:

<label for="ProgramAudience">Intended Audience:</label>
                <span><input type="checkbox" name="ProgramAudience[]" value="AcademicAffairsFaculty" />Academic Affairs/Faculty</span>
                <span><input type="checkbox" name="ProgramAudience[]" value="StudentAffairsDevelopment" />Student Affairs/Development</span>
                <span><input type="checkbox" name="ProgramAudience[]" value="CommunityCollege" />Community College/2-Year Institutions</span>
                <span><input type="checkbox" name="ProgramAudience[]" value="GraduateStudents" />Graduate Students</span>
                <span><input type="checkbox" name="ProgramAudience[]" value="FourYearPublic" />Four-Year Public Institutions</span>
                <span><input type="checkbox" name="ProgramAudience[]" value="FourYearPrivate" />Four-Year Private Institutions</span>



<label for="ExpectedOutcome">Expected Learning Outcomes:</label>
                <label class="small">List 1-2 expected learning outcomes below. (As a result of attending this session, participants will...)</font></label>
                    <font size="1" face="arial, helvetica, sans-serif"> ( You may enter up to 400 characters. )<br>
                <textarea name="message4" id="ExpectedOutcome" class="required" wrap="physical" rows="10" cols="35" onKeyDown="textCounter(this.form.message4,this.form.remLen,400);" onKeyUp="textCounter(this.form.message4,this.form.remLen,400);"></textarea>

以下是处理文件的一部分:

$ProgramAudience = $_POST['ProgramAudience']; 
$ExpectedOutcome = $_POST['ExpectedOutcome']; 

...

$Body = "";
$Body .= "ProgramAudience: ";
$Body .= $ProgramAudience;
$Body .= "\n";
$Body .= "ExpectedOutcome ";
$Body .= $ExpectedOutcome;

这是电子邮件结果的样子:

来自:

致:me@me.net

日期:星期四,2010年7月15日17:10:17 -0400

主题:提案提交

名字:英里

姓氏:我

标题:测试

机构:测试

EmailFrom:me@me.net

电话:8157531503

地址:HSC 023A

城市:DeKalb

状态:IL

邮编:60115

CoPresenter:adam

ProgramTitle:

ProgramType:Array

ProgramDescription:

ProgramOutline:

ProgramTopic:Array

ProgramAudience:Array

ExpectedOutcome

经验:

AVEquipment:

2 个答案:

答案 0 :(得分:1)

检查文本区域的名称属性 - 这是PHP将使用的属性。

复选框只有在选中后才能通过,所以请务必检查一下。使用带括号的名称,如“ProgramAudience []”,$ _POST ['ProgramAudience']变量将为null或数组。您需要检查它是否是一个数组,如果是,请遍历内容以生成您的电子邮件。

答案 1 :(得分:1)

对于复选框数组,处理脚本需要:

$ProgramTitle = $_POST['ProgramTitle']; 
foreach($_POST['ProgramType']  as  $value)  {
$check_msg .= "Checked: $value\n";
} 

和此:

$Body .= "ProgramTitle: ";
$Body .= $ProgramTitle;
$Body .= "\n";
$Body .= "ProgramType: ";
$Body .= $check_msg;