Step: 1
Please change the code in controller file as below
Step 2:
Change the code in controller section
From =
if (!empty($post)) {
$name = $post['name'];
$age = $post['age'];
$weight = $post['weight'];
$height = $post['height'];
$gender = $post['gender'];
$product_id = $post['product_id'];
$customer_id = $post['customer_id'];
$model = $this->_objectManager->create('Softadroit\Prescription\Model\Prescription');
/* $model->setName($name);
$model->setAge($age);
$model->setWeight($weight);
$model->setHeight($height);
$model->setGender($gender);
$model->setGender($product_id);
$model->setGender($customer_id); */
$model->setData([
"name" => $name,
"age" => $age,
"weight" => $weight,
"height" => $height,
"gender" => $gender,
"product_id" => $product_id,
"customer_id" => $customer_id
]);
/* echo "<pre>";
print_r($model);
die(); */
$msg ="";
$data = $model->save();
if($data != ''){
//$model->save();
$this->messageManager->addSuccessMessage('Thanks your form is submitted successfully!');
}else{
$this->messageManager->addSuccessMessage('Error in submitting data. Please contact on this email!');
}
echo $msg;
// Redirect to your form page (or anywhere you want...)
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$resultRedirect->setUrl('/prescription/index');
return $resultRedirect;
}
To=
if (!empty($post)) {
foreach($post['name'] as $key => $name) {
$age = $post['age'][$key];
$weight = $post['weight'][$key];
$height = $post['height'][$key];
$gender = $post['gender'][$key];
$product_id = $post['product_id'][$key];
$customer_id = $post['customer_id'][$key];
$model = $this->_objectManager->create('Softadroit\Prescription\Model\Prescription');
$model->setData([
"name" => $name,
"age" => $age,
"weight" => $weight,
"height" => $height,
"gender" => $gender,
"product_id" => $product_id,
"customer_id" => $customer_id
]);
$msg ="";
$data = $model->save();
if($data != ''){
//$model->save();
$this->messageManager->addSuccessMessage('Thanks your form is submitted successfully!');
}else{
$this->messageManager->addSuccessMessage('Error in submitting data. Please contact on this email!');
}
}
echo $msg;
// Redirect to your form page (or anywhere you want...)
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$resultRedirect->setUrl('/prescription/index');
return $resultRedirect;
}