merchant:epaymentform:reqfieldsjavascript

Required Fields with Javascript

This code uses Javascript to make fields required. It is similar to Required Field prompts except that it indicates which fields are required when the customer lands on the payment form. Another difference is that after it validates the form, it provides inline instructions for the customer as opposed to instructions in an alert box. It has the same advantage Required Field prompts has as opposed to use of source key settings because it keeps the customer on the same page if the required fields are blank. Some web browsers will erase all form data if the customer uses the back page to return to the form.

  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: ";
      themessage = themessage + "<ul>";
      if (document.epayform.UMname.value=="") {
      themessage = themessage + "<li>Cardholder Name</li>";
      }
      if (document.epayform.UMcard.value=="") {
      themessage = themessage + "<li> Card Number</li>";
      }
      if (document.epayform.UMexpir.value=="") {
      themessage = themessage + "<li> Card Expiration Date</li>";
      }
      themessage = themessage + "</ul>";
      //alert if fields are empty and cancel form submit
      if (themessage == "Please complete the following fields: <ul></ul>") {
      document.epayform.submit();
      return true;
      }
      else {
      document.getElementById('required').innerHTML = "<font color=\"#FF0000\">" + themessage + "</font>";
      window.scrollTo(0,0);
      return false;
       }
      }
      </script>
  3. You can make as many fields required as you want. To make a field required, repeat this section of code. Please note, requiring fields that are not on your payment form will break the entire field verification, causing no field requirements:
    1. if (document.epayform.UMfield.value=="") {
      themessage = themessage + "<li> Name of Field</li>";
      }
  4. Create inline instructions
    1. Find
      1. <tr>
            <td bgcolor="#F0F0F0" width="692" colspan="2">&nbsp;</td>
        </tr>
    2. Replace it with
      1. <tr>
           <td bgcolor="#F0F0F0" width="692" colspan="2" align="center">
         
              <table>
             <tr>
            <td>
            <div id="required"><font size="2" face="Verdana" color="#ff0000">*</font><font size="2" face="Verdana"> indicates a required field.</font></div>&nbsp;
            </td>
            </tr>
            </table>
         
           </td>
        </tr>
  5. Create red *s
    1. Find
      1. <td bgcolor="#F0F0F0" width="450">
        <input type="text" name="UMname" size="25" value="[UMname]"></td>
    2. Replace it with
      1. <td bgcolor="#F0F0F0" width="450">
        <input type="text" name="UMname" size="25" value="[UMname]"> <font face="Verdana" size="2"color="#ff0000">*</font></td>
    3. Find
      1. <tr>
            <td bgcolor="#F0F0F0" width="234" align="right"><font face="Verdana" size="2">Card Number:</font></td>
            <td bgcolor="#F0F0F0" width="450">
            <input type="text" name="UMcard" size="17"></td>
        </tr>
        <tr>
            <td bgcolor="#F0F0F0" width="234" align="right"><font face="Verdana" size="2">Card Expiration Date: </font></td>
            <td bgcolor="#F0F0F0" width="450">
            <input type="text" name="UMexpir" size="4"> MMYY</td>
        </tr>
    4. Replace it with
      1. <tr>
            <td bgcolor="#F0F0F0" width="234" align="right"><font face="Verdana" size="2">Card Number:</font></td>
            <td bgcolor="#F0F0F0" width="450">
            <input type="text" name="UMcard" size="17"> <font face="Verdana" size="2"color="#ff0000">*</font></td>
        </tr>
        <tr>
            <td bgcolor="#F0F0F0" width="234" align="right"><font face="Verdana" size="2">Card Expiration Date: </font></td>
            <td bgcolor="#F0F0F0" width="450">
            <input type="text" name="UMexpir" size="4"> MMYY <font face="Verdana" size="2"color="#ff0000">*</font></td>
        </tr> 
    5. For every additional field, find
      1.  <input type="text" name="UMfield" size="x" value="[UMfield]">
    6. Replace it with
      1.  <input type="text" name="UMfield" size="x" value="[UMfield]"> <font face="Verdana" size="2"color="#ff0000">*</font>
  6. Modify submit button
    1. Find
      1. <input type="submit" name="submitbutton" value="Process Payment &gt;&gt;">
    2. Replace it with
      1. <input type="submit" name="submitbutton" value="Process Payment &gt;&gt;" onclick="return verify();">
  7. 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/reqfieldsjavascript.txt · Last modified: 2017/04/25 15:28 by kat

Page Tools