0

my phtml file code (below input tag is in for loop i=0 to i<5)

       <input type="text" name="array[]" value="<? echo $i ;?>" data-form-part='product_form'>

observer code

public function execute(\Magento\Framework\Event\Observer $observer) {

    $_product = $observer->getProduct();  // you will get product object
    
    $post = $this->_request->getPostValue();
    
    var_dump($post['array']);die();
    
    
}

after save product only print last value of arrayenter image description here

1 Answer 1

0

Welcome to Magento Stack Exchange!

Give the key to the array when iterates.

<input type="text" name="array[<? echo $i ;?>]" value="<? echo $i ;?>" data-form-part='product_form'>

Otherwise it will take only the last element of the array, keys are overwriting with empty in each iteration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.