表格上的php表单验证 [英] php form validation on table

查看:63
本文介绍了表格上的php表单验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表格中具有表格名称的教育资格.我想在资格表上进行验证.他们总共有5个字段供用户决定填写.但是我需要进行验证,如果用户输入通过的考试,那么他将必须添加通过的考试的所有详细信息.

例如 行考试通过年分数百分比
1 10 200 170 60
2 12
3
4
5

在此表中有5行,但用户必须决定要填充多少列...但是,如果用户输入空行(例如"12"),则需要输入年份标记和百分比.

  foreach ($ post ['  as  如果(空($ exam_passed_)){
      $ error [] = '  exam_passed _'.  $ id ;
      $ error_message [] = '  exam_passed_不能为空.';
    }
  }


 foreach ($ post ['  univ' ]  as   $ id  => $ slno){
    如果(空($ univ_)){
      $ error [] = '  univ _'.  $ id ;
      $ error_message [] = '  univ_不能为空.';
    }
  }

 foreach ($ post ['  years_passing' ]  as   $ id  => $ slno){
    如果(空($ years_passing_)){
      $ error [] = '  years_passing _'.  $ id ;
      $ error_message [] = '  years_passing_不能为空.';
    }
  }

 foreach ($ post [' 尝试' ]  as   $ id  => $ slno){
    如果(empty($ attempt_)){
      $ error [] = '  attempt _'.  $ id ;
      $ error_message [] = '  attempt_不能为空.';
    }
  }

 foreach ($ post ['  max_marks' ]  as   $ id  => $ slno){
    如果(空($ max_marks_)){
      $ error [] = '  max_marks _'.  $ id ;
      $ error_message [] = '  max_marks_不能为空.';
    }
  }


<   pre     ="   xml" <  > ; 学历:(考试从Metic/高中开始升至博士学位/研究学位).
                        <      ="   5px" 边框   1" > 
                          <   thead  > 
                            <   tr  > 
                              <   td  > 
                              <  中心 > 考试<  /center  > 
                              <  /td  > 
                              <   td  > 
                              <   center  > 名称Univ./Board<  /center  > 
                              <  /td  > 
                <   td  > 
                              <  中心 > 通过年份<  /center  > 
                              <  /td  > 
                <   td  > 
                              <   center  > 尝试通过<  /center  > 
                              <  /td  > 
                              <   td  > 
                              <  中心 > 最大值.标记<  /center  > 
                              <  /td  > 

                              <   td  > 
                              <  中心 > 获得的标记<  /center  > 
                              <  /td  > 
                              <   td  > 
                              <  中心 > 百分比<  /center  > 
                              <  /td  > 
                <   td  > 
                              <   center  > 荣誉区分(位置)<  /center  > 
                              <  /td  > 
                            <  /tr  > 
                          <  /thead  > 
                          <  正文 > 
                           <? php  for ($ i =  0 ; $ i< 13; $ i ++):?> 
                            <   tr  > 

                              <   td  > 
<   div        .    $ i,    $ error)   ?   打印    错误'    : span>   '') ?  <  输入   类型  ="    名称  ="    ="  > ;  <  /td  > 
                              <   td  > 
<   div        .    $ i,    $ error)   ?   打印    错误'    : span>   '') ?  <  输入   类型  ="    名称  ="    ="  > ;  <  /td  > 

                              <   td  > 
<   div        .    $ i,    $ error)   ?   打印    错误'    : span>   '') ? <     ="    名称  ="      ="  > ;  <  /td  > 
                <   td  > 
<   div        .    $ i,    $ error)   ?   打印    错误'    : span>   '') ?  <  输入   类型  ="    名称  ="    ="  > ;  <  /td  > 
                <   td  > 
<   div        .    $ i,    $ error)   ?   打印    错误'    : span>   '') ?  <  输入   类型  ="    名称  ="    ="  > ;  <  /td  > 
                <   td  > 
<   div        .    $ i,    $ error)   ?   打印    错误'    : span>   '') ?  <  输入   类型  ="    名称  ="    ="  > ;  <  /td  > 
                              <   td  > 
<   div        .    $ i,    $ error)   ?   打印    错误'    : span>   '') ?  <  输入   类型  ="    名称  ="    ="  > ;  <  /td  > 
                              <   td  > 
<   div        .    $ i,    $ error)   ?   打印    错误'    : span>   '') ?  <  输入   类型  ="    名称  ="    ="  > ;  <  /td  > 
                            <  /tr  > 
                            <? php endfor; ?> 

                          <  /tbody  > 
                        <  /table  > 
                        <  /li  >  

解决方案

post [' exam_passed' span>] as


id =>

slno){ 如果(空(


i have a table name education qualification in my form. i want validation on qualification table. they have total 5 fields out of which user decide to fill. but i need validation on, if a user enter exam passed then he will have to add all details of exam passed.

for e.g
row exam passed year marks percentage
1 10 200 170 60
2 12
3
4
5

in this table there are 5 rows but user have to decide how many columns are going to fill... but if user enter in empty row like "12" so he need to enter year marks and percentage.

foreach ($post['exam_passed'] as $id => $slno) {
    if (empty($exam_passed_))  {
      $error[] = 'exam_passed_' . $id;
      $error_message[] = 'exam_passed_ can not be blank.';
    }
  }


foreach ($post['univ'] as $id => $slno) {
    if (empty($univ_)) {
      $error[] = 'univ_' . $id;
      $error_message[] = 'univ_ can not be blank.';
    }
  }

foreach ($post['years_passing'] as $id => $slno) {
    if (empty($years_passing_)) {
      $error[] = 'years_passing_' . $id;
      $error_message[] = 'years_passing_ can not be blank.';
    }
  }

foreach ($post['attempt'] as $id => $slno) {
    if (empty($attempt_)) {
      $error[] = 'attempt_' . $id;
      $error_message[] = 'attempt_ can not be blank.';
    }
  }

foreach ($post['max_marks'] as $id => $slno) {
    if (empty($max_marks_)) {
      $error[] = 'max_marks_' . $id;
      $error_message[] = 'max_marks_ can not be blank.';
    }
  }


<pre lang="xml"><li> Academic Qualification:(Examinations passed from Metic/Higher Secondary onwards to Doctorate/Research degrees).
                        <table cellpadding="5px" border="1">
                          <thead>
                            <tr>
                              <td>
                              <center>Examination</center>
                              </td>
                              <td>
                              <center>Name of the Univ./Board</center>
                              </td>
                <td>
                              <center>Year of Passing</center>
                              </td>
                <td>
                              <center>Attempts in which passed</center>
                              </td>
                              <td>
                              <center>Max. Marks</center>
                              </td>

                              <td>
                              <center>Marks Obtained</center>
                              </td>
                              <td>
                              <center>Percentage</center>
                              </td>
                <td>
                              <center>Hons Distinction(Position)</center>
                              </td>
                            </tr>
                          </thead>
                          <tbody>
                           <?php for ($i = 0; $i<13; $i++): ?>
                            <tr>

                              <td>
<div <?php (in_array('exam_passed_' . $i, $error) ? print "class='error'" : '') ?>><input type="text" name="exam_passed[]" value="<?php !empty($post['exam_passed'][$i]) ? print $post['exam_passed'][$i] : '';?>"/></td>
                              <td>
<div <?php (in_array('univ_' . $i, $error) ? print "class='error'" : '') ?>><input type="text" name="univ[]" value="<?php !empty($post['univ'][$i]) ? print $post['univ'][$i] : '';?>"/></td>

                              <td>
<div <?php (in_array('years_of_passing_' . $i, $error) ? print "class='error'" : '') ?>><input type="text" name="years_passing[]" value="<?php !empty($post['years_passing'][$i]) ? print $post['years_passing'][$i] : '';?>"/></td>
                <td>
<div <?php (in_array('attempt_' . $i, $error) ? print "class='error'" : '') ?>><input type="text" name="attempt[]" value="<?php !empty($post['attempt'][$i]) ? print $post['attempt'][$i] : '';?>"/></td>
                <td>
<div <?php (in_array('max_marks_' . $i, $error) ? print "class='error'" : '') ?>><input type="text" name="max_marks[]" value="<?php !empty($post['max_marks'][$i]) ? print $post['max_marks'][$i] : '';?>"/></td>
                <td>
<div <?php (in_array('marks_obt_' . $i, $error) ? print "class='error'" : '') ?>><input type="text" name="marks_obt[]" value="<?php !empty($post['marks_obt'][$i]) ? print $post['marks_obt'][$i] : '';?>"/></td>
                              <td>
<div <?php (in_array('percentage_' . $i, $error) ? print "class='error'" : '') ?>><input type="text" name="percentage[]" value="<?php !empty($post['percentage'][$i]) ? print $post['percentage'][$i] : '';?>"/></td>
                              <td>
<div <?php (in_array('position_' . $i, $error) ? print "class='error'" : '') ?>><input type="text" name="position[]" value="<?php !empty($post['position'][$i]) ? print $post['position'][$i] : '';?>"/></td>
                            </tr>
                            <?php endfor; ?>

                          </tbody>
                        </table>
                        </li>

解决方案

post['exam_passed'] as


id =>


slno) { if (empty(


这篇关于表格上的php表单验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆