0

i have a form it's like assign a product through frontend. but my doubt is after that how i validate

<form action="<?php echo $this->getUrl('mpassignproduct/index/edit') ?>" enctype="multipart/form-data" method="post" id="form-customer-product-edit">

<li class="fields">
<div class="customer-name">
<div class="field">
<label class="required" for="sku"><em>*</em><?php echo $helper->__('Sku')?></label>
<div class="input-box">
<input type="text" name="sku" id="sku" class="required-entry input-text" value="<?php echo $mpAssignProductModel->getsku() ?>"/></div></div></div></li>
</form>

i upload to this form and store it db my problem if same sku also upload how i restrict that.

1

You should first validate any data on forms using a client side validation like javascript. If you have more complex functions like a duplicate lookup you can accomplish this through an AJAX call to the database to see if that value already exists.

Finally, you should also validate your data in your model to ensure that you are not going to throw an error on the database insert.

Of course you should also do a catch on your function to capture any potential errors and report them via the Magento log function.

| improve this answer | |
  • can you please send me any example or code – Magento 2 Nov 5 '15 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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