2016-05-27 7 views
1

では動作しません、私はそうのような形式になります!フォーム入力配列が空の配列を作成して、空の()

 <div class="clone-wrapper" data-id="education"> 
      <div class="row cloneable" data-id="0">    
       <div class="col-md-6"> 
        <div class="form-group"> 
         <label><?php echo System::translate("Education Institution Name"); ?></label> 
         <input placeholder="<?php echo System::translate("ex : University"); ?>" name="education[0][institution]" type="text" class="max_len" maxlength="100" value=""> 
        </div> 
       </div> 
       <div class="col-md-6"> 
        <div class="form-group"> 
         <label><?php echo System::translate("Education Degree"); ?></label> 
         <input placeholder="<?php echo System::translate("ex : Bachelor Degree"); ?>" name="education[0][degree]" type="text" class="max_len" maxlength="100" value=""> 
        </div> 
       </div> 


       <div class="col-md-6"> 
        <div class="form-group"> 
         <label><?php echo System::translate("Date of Enrollment"); ?></label> 
         <input placeholder="<?php echo System::translate("ex : January 2001"); ?>" name="education[0][year_begin]" type="text" class="monthyearpicker" autocomplete='off' value=""> 
        </div> 
       </div> 
       <div class="col-md-6"> 
        <div class="form-group"> 
         <label><?php echo System::translate("Date of Completion"); ?></label> 
         <input placeholder="<?php echo System::translate("ex : December 2004"); ?>" name="education[0][year_finish]" type="text" class="monthyearpicker" autocomplete='off' value=""> 
        </div> 
       </div> 

       <div class="col-md-12"> 
        <div class="form-group"> 
         <label><?php echo System::translate("Education Note"); ?></label> 
          <textarea rows="6" class="form-control" name="education[0][about]"></textarea> 
        </div> 
       </div> 
      </div> 
     </div> 
     <div class="white-space-20"></div> 
     <div class="row text-right"> 
      <div class="col-md-12"> 
       <div class="btn btn-default btn-sm clonable-button" data-clone="education"> 
        <i class="fa fa-plus"></i><?php echo System::translate("Add Education"); ?></div> 
      </div> 
     </div> 

あなたは私がeducation[0][inputname]のような名前の配列を使用しています見ることができるようになりました、私の問題がありますこれは値のない配列を作成しているので、入力に値を入力していないかどうかを確認することはできません。それは返します

Array 
(
    [0] => Array 
     (
      [company] => 
      [title] => 
      [year_begin] => 
      [year_finish] => 
      [country] => 
      [notes] => 
     ) 

) 

私は上!empty()を使用できるように、それは空の配列を返すことができますどのように?

+0

をあなたは '教育が必要です[0]' [について] ?あなたは単に 'education [about]'などを使うことができます。次に 'array_filter()'を使います。 – AbraCadaver

+0

ええ、複数の同じ入力があります。 –

答えて

0

ただ、空の要素をフィルタリングして確認してください。

if(empty(array_filter($_POST['education'][0]))) { 
    // array is empty 
} 

あなたは、任意の空の要素をチェックする必要がある場合:

if(count(array_filter($_POST['education'][0])) != count($_POST['education'][0])) { 
    // one or more elements are empty 
}