Required Fields via Javascript Validation

This code will allow you to use Javascript to make fields required, rather than the source key settings. You may want to use this rather than the built-in required fields settings as an alternate way of requiring those fields to be filled out. The main difference between this and our built-in required fields handling is that this will ensure fields are filled out before the customer leaves the page - some web browsers will erase all data if the customer leaves the page.

  1. Log into your USAePay merchant gateway. Go to “Settings”, then “Source Keys”. Select the source key you are using and click “Edit”. Click “Edit Customization to Epay Form”.
  2. Insert this code into the document head:
    1. <script>
      function verify() 
      var themessage = "Please complete the following fields: ";
      if (document.epayform.UMname.value=="") {
      themessage = themessage + " - Cardholder Name";
      //alert if fields are empty and cancel form submit
      if (themessage == "Please complete the following fields: ") {
      return true;
      else {
      return false;
  3. You can make as many fields required as you want. To make a field required, repeat this section of code:
    1. if (document.epayform.UMfield.value=="") {
      themessage = themessage + " - Name Of Field";
  4. Scroll down to the bottom of the form and look for this line:
    1. <input type="submit" name="submitbutton" value="Process Payment &gt;&gt;">
  5. Change it to read:
    1. <input type="submit" name="submitbutton" value="Process Payment &gt;&gt;" onclick="return verify();">
  6. If the required field you want to add is also under the hidden fields section at the top of the form, remove the hidden field's line in accordance to the field. If the field you chose isn't in the hidden fields section you do not have to do this step.

Example : UMinvoice as a required field. UMinvoice is in the hidden fields section.

  • Delete from Hidden Fields Section :
<input type="hidden" name="UMinvoice" value="[UMinvoice]"> 
merchant/epaymentform/reqfields.txt · Last modified: 2015/05/22 08:38 by kat

Page Tools