With the help of @AmitSaini i figured out.
I am currently using Magento 2.3.6
How to "add to cart" a product with custom input field and save it to Database?
Follow this link and check Renon Stewart answer.
If you get in Product View this error: {"message":"Unable to unserialize value. Error: Syntax error"}
or
if you get the jQuery error: Uncaught Error: [object Object]
Change in the inside of SalesModelServiceQuoteSubmitBeforeObserver.php and CheckoutCartProductAddAfterObserver.php :
serialize to json_encode
and
unserialize to json_decode
Now the next problem. If you tried before to go to the checkout with serialze and you were logged in with an user account, you need to delete the last quote item.
You need to delete in the database inside the quote table the last quote with the used e-mail.
Hint:
$post = $this->_request->getParam('cloudways');
This line, parameter defines the "name" field inside the addtocart.phtml responsible for this input field:
<input type="text" name="cloudways[remarks]" id="remarks" maxlength="255" placeholder="Remarks" />
"remarks" in this case is the json configuration name field.
And one more thing.
If you can't complete the checkout process, change the
SalesModelServiceQuoteSubmitBeforeObserver.php file on line 50:
if(count($additionalOptions) > 0)
to:
if(is_array($additionalOptions) && count($additionalOptions) > 0){