douheng8629 2010-03-20 21:47 采纳率: 100%
浏览 24

帮助验证规则

I am trying to figure out how to validate a section of a form using php. If at least one of value 1-5 is checked, then at least one of value A-E must be checked. Value's A-E cannot be allowed without at least one of 1-5 being checked. Multiple values in each section can be selected, as long as there is at least one value in each section checked.

I have tried individual IF statements and arrays without success.

Does anyone have any suggestions or examples? I am missing something and I am certain it is pretty obvious, right in my face.

 <div class="grid_12 alpha">
<strong>DISMISSAL</strong> - This section is to be used for errors which require dismissal by a Judge.
</div>

<div class="grid_5 alpha">
<input class="checkbox" type="checkbox" name="dis_checkbox_a" />A
&nbsp;
<input class="checkbox" type="checkbox" name="dis_checkbox_b" />B
&nbsp;
<input class="checkbox" type="checkbox" name="dis_checkbox_c" />C
&nbsp;
<input class="checkbox" type="checkbox" name="dis_checkbox_d" />D
&nbsp;
<input class="checkbox" type="checkbox" name="dis_checkbox_e" />E
</div>

<div class="grid_3">
<input class="checkbox" type="checkbox" name="dis_checkbox_mon" />Missing Officers Name
</div>

<div class="grid_4 omega">
<input class="checkbox" type="checkbox" name="dis_checkbox_civ_crim_error" />Criminal/Civil Designation in Error
</div>

<div class="grid_12 alpha">
<input class="checkbox" type="checkbox" name="dis_checkbox_improp_code_descr" />Improper Statute Number AND Description
</div>

<div class="grid_12 alpha">
<input class="checkbox" type="checkbox" name="dis_checkbox_other" />Other
<input id="input" type="text" name="dis_cit_other" size="115" maxlength="110" onkeypress="checkCapsLock( event )" />
</div>

<div class="grid_6 alpha">
Citing Officer:
<input id="input" type="text" name="dis_cit_officer" size="5" maxlength="5" onkeypress="checkCapsLock( event )" />
(Enter PR# only)
</div>

<div class="grid_6 omega">
Supervisor Notified:
<input id="input" type="text" name="dis_supvsr_notified" size="5" maxlength="5" onkeypress="checkCapsLock( event )" />
(Enter PR# only)
</div>
  • 写回答

1条回答 默认 最新

  • dsyo9700 2010-03-21 04:15
    关注
    $number_boxes = array($_POST['box1'], $_POST['box2'], $_POST['box3'], $_POST['box4'], $_POST['box5']);
    
    $letter_boxes = array($_POST['box_a'], $_POST['box_b'], $_POST['box_c'], $_POST['box_d'], $_POST['box_e']);
    
    function validateCheckboxes($number_boxes, $letter_boxes){
    
        $numbers_checked = FALSE;
        $letters_checked = FALSE;
    
        foreach($number_boxes as $val){
            if($val) $numbers_checked = TRUE;
        }
    
        foreach($letter_boxes as $val){
            if($val) $letters_checked = TRUE;
        }
    
        if ($numbers_checked && !$letters_checked){
            return FALSE;
        } else if(!$numbers_checked && $letters_checked){
            return FALSE;
        } else {
            return TRUE;
        }
    }
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作