I unten Felder angelegt haben, in meinem form-CakePHP Validierungsproblem für dynamische Felder
<input type="text" id="ProductPrice1" class="small" name="data[Product][price][1]">
<input type="text" id="ProductPrice1" class="small" name="data[Product][price][2]">
<input type="text" id="ProductPrice1" class="small" name="data[Product][price][3]">
<input type="text" id="ProductPrice1" class="small" name="data[Product][price][4]">
Jetzt versuche ich, unten Modellvalidierung für über Felder hinzufügen, indem Sie funktions-
public function productValidates() {
$validate= array();
$validate = array(
'name'=> array(
'mustNotEmpty'=>array(
'rule' => 'notEmpty',
'message'=> __('PRODUCTS.TITLE_BLANK_ERROR',true)
)
),
'description'=> array(
'mustNotEmpty'=>array(
'rule' => 'notEmpty',
'message'=> __('PRODUCTS.DESCRIPTION_BLANK_ERROR',true)
)
),
'category_id'=> array(
'mustNotEmpty'=>array(
'rule' => 'notEmpty',
'message'=> __('PRODUCTS.SELECT_CATEGORY_ERROR',true)
)
),
);
$count = $this->data[$this->name]['total_prices'];
for($i=1; $i<= $count;$i++){
$validate['price'][$i] = array(
'1' => array(
'rule' => array('notEmpty',true),
'message' => __('PRODUCTS.PRICE_EMPTY_ERROR',true),
'last' => true
)
);
}
$this->validate = $validate;
return $this->validates();
}
Aber sein funktioniert nicht.
Können Sie bitte vorschlagen, was ist das Problem hier?
Zwar ist dies nicht das einzige Problem sein könnte , Sie haben dieselbe ID in mehreren HTML-Eingabeelementen angegeben. – user221931
Sie haben Recht, ich habe die gleiche ID gegeben, aber das ist nicht mit dem Kuchen Validierung Fehler, den ich verlange. –