目前正在使用Bitrix CMS,需要为特定群组的用户投票。通过知道组的ID,我在里面制作了一堆带有单选按钮的表单。当有人投票时,结果应该写在文件(或数据库)和页面中"感谢您投票!"应该显示。
我的问题是最好的方法是什么?
我尝试了几种不同的方式:
1)this tutorial,不工作
2)另外两个网络教程,如果你问我可以链接
3)从bitrix投票表格,但系统的那个模块应该改变,而不建议。
下面是投票本身的页面,但" poll.php"因为不知道正确的方式让我感到困惑。如此好的建议将非常感激。
P.S。你可以忽略' Bitrix'部分,最重要的是php
/*get users from group in array*/
<?$arUsers = CGroup::GetGroupUser(20);
$iCountUsers = 0;
$arUsersbyGroupID = array();
foreach($arUsers as $arUser) {
$arUserbyID = CUser::GetByID($arUser);
$rsUserbyID = $arUserbyID -> Fetch();
$arUsersbyGroupID[] = $rsUserbyID; }
$iCountUsers++;?>
<div class="wrapper">
<div id="poll-container">
<form class="grid" action="poll.php" method="post" accept-charset="utf-8">
/*for each create element with radio button*/
<?$iVoteCount = 0;
$allopt = array();
foreach($arUsersbyGroupID as $Vote) {
$photo = $Vote["PERSONAL_PHOTO"];
if (!empty($photo)) {
$name = "{$Vote["NAME"]} {$Vote["LAST_NAME"]}";?>
<div class="cell">
<div class="cell_img"><?echo CFile::ShowImage($photo)?></div>
<div class="cell_caption">
<input type="radio" value="<?=$iVoteCount?>" name="vote" onclick="getVote(this.value)" />
<label for='opt<?=$iVoteCount?>'><?echo $name?></label>
</div>
</div>
$iVoteCount++;
}
} ?>
<div id="sub"><input type="submit" value="Vote" /></div>
</form>
</div>
</div>
&#13;
答案 0 :(得分:0)
您不应该编写完全自定义的解决方案来创建民意调查。在Bitrix Framework中,我们有一个名为 - vote
通过提供此模块,您可以创建标准民意调查,或者如果它们不适合您的任务 - 您可以自定义它们,但您不应该从头开始编写所有这些代码。
对于基本民意调查配置,您可以阅读官方在线课程(俄语) - http://dev.1c-bitrix.ru/learning/course/index.php?COURSE_ID=41&LESSON_ID=2859
答案 1 :(得分:0)
使用bitrix api传输数组数据,使用$ _POST或$ _REQUEST全局变量将它们绑定到自定义表单名称[]。只需在提交事件后添加bitrix api代码。投票结果可以粘贴到以前应该手动在BX中创建的自定义潜在客户字段中。看看这个例子。它完全可行并经过测试。
<?php
$queryUrl ='';
$_SERVER['REMOTE_ADDR'] = $ip;
$queryData = http_build_query($basebitrix24 = array(
'fields' => array(
"TITLE" =>'one',
"NAME" => 'two',
"LAST_NAME" => $leadData['question_one'],
"STATUS_ID" => "NEW",
"OPENED" => "Y",
"UF_CRM_1491235024" => $leadData['question_second'],
"UF_CRM_1491235124" => $leadDataQ1[$answer],
"UF_CRM_1491235376" => $leadData['question_third'],
"ASSIGNED_BY_ID" => 16,
'SOURCE_ID' => $i,
"PHONE" => array(array("VALUE" => $_REQUEST['phone'], "VALUE_TYPE" => "WORK" )),
"EMAIL" => array(array("VALUE" => $_REQUEST['email'], "VALUE_TYPE" => "WORK" )),
),
'params' => array("REGISTER_SONET_EVENT" => "Y")
));
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_POST => 1,
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $queryUrl,
CURLOPT_POSTFIELDS => $queryData,
));
$result = curl_exec($curl);
curl_close($curl);
$result = json_decode($result, 1);
?>
请求不是关于投票,但是对于任何自定义表单使用相同的方法也没有太大的麻烦。示例目的中的表单代码
if (isset($_POST['s_submit'])) {
@$email = strtolower(trim($_POST['email']));
@$name = trim($_POST['name']);
if (isset($_POST) && count($_POST) != 0) {
if (@isset($email) && @$email != '') {
$line = check_record_exist($removelist, $email, $form_type);
if ($line) {
$line--;
delete_line_from_file($removelist, $line);
}
if (!check_record_exist($addlist, $email, $form_type)) {
add_record($addlist, $email, $name);
$sm_res = 1;
} else {
$sm_res = 3;
}
} else
echo '<font color="#FF0000">Please enter e-mail address</font>';
}
}
if (isset($sm_res)) {
switch ($sm_res) {
case '1': echo '<b>You have successfully subscribed</b>';
break;
case '2': echo '<b>You have successfully unsubscribed</b>';
break;
case '3': echo '<b>You are already subscribed</b>';
break;
case '4': echo '<b>You are already unsubscribed</b>';
break;
}
unset($sm_res);
} else {
<form name="contactform" id="sky-form" method="post" action="">
<fieldset>
<div class="row">
<div class="sky-form epochta">
<section class="col col-6" >
<label class="input"><i class="icon-append icon-envelope-alt"></i> <h3>EMAIL </h3><input type="email" name="email" value="<?$_REQUEST['email']?>"> </label>
</section>
<?php if ($form_type != 1) { ?>
<section class="col col-6">
<label class="input"> <i class="icon-append icon-user"></i><h3>NAME<h3> <input type="text" name="name" size="15" value="<?php echo @trim(strip_tags($_REQUEST['name'])); ?>">
</label>
</section>
<?php } ?>
<section class="col col-12" >
<input type="hidden" name="saved" value="yes">
<input type="submit" class="subbutton" name="submit" value="">
<td align="center" colspan="2"><a href="http://www.epochta.ru/products/subscription/" target="_blank"><font face="Verdana" size="-2">ePochta Subscription Manager</font></a>
</section>
</div>
</div>
</fieldset>
</form>
?>