Ensure empty values are not submitted
Name attributes specify the name of particular html elements. In the case of gift messages obtained through Giftship, your customer may have filled in fields with name attributes such as ‘To’, ‘From’, and ‘Message’.
If you would like to remove these from being submitted, when empty, disabling the field before the form is submitted is the best way to do so.
To remove empty values from the form go to Online Store -> Themes -> Your Theme -> theme.liquid, and insert the following code above the closing </body> tag:
<script>
(function() {
var GSM = {
init: function() {
GSM.assignElements();
GSM.events();
},
elements: {
productForm: null,
formSubmitButton: null,
},
state: {
form_handled: false
},
assignElements: function() {
GSM.elements.productForm = document.querySelector('form[action*="cart/add"]');
GSM.elements.formSubmitButton = document.querySelector('button[id*="AddToCart--product-template"]');
},
events: function() {
GSM.elements.productForm.addEventListener('submit', GSM.functions.handleFormSubmit);
},
functions: {
handleFormSubmit: function(event) {
if (GSM.state.form_handled === true) {
return true;
}
GSM.state.form_handled = true;
GSM.functions.removeAttributes();
GSM.elements.formSubmitButton.click();
event.preventDefault();
},
removeAttributes: function() {
var giftshipInputs = GSM.elements.productForm.querySelectorAll('.gs__product-element');
giftshipInputs.forEach(function(el) {
if (el.value !== "") return;
el.setAttribute('disabled', 'disabled');
});
}
}
}
GSM.init();
})();
</script>
Can't find the answer in our documentation?
Contact Support Configuring Gift Messages 🏷️
Printing Gift Messages 🏷️
Conditionally Hide the Gift Message Option on Product Pages 🏷️
Editing a Gift Message After an Order Has Been Placed 🏷️
How to view orders that contain Gift Messages or Delivery Dates 🏷️
Use Shopify’s Packing Slip to Print Gift Messages 🏷️
How to Charge for a Gift Message 🏷️
Remove Name Attributes from Gift Messages 🏷️
How to Display a Gift Message on Your Cart Page When it was Added on Your Product Page 🏷️
Change the location of where the gift message appears on your orders to the order Notes section 🏷️
Ensure empty values are not submitted
Shopify Plus: Loading Giftship’s Features on the Checkout Page