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.
- Log into your eBizCharge merchant gateway. Go to “Settings”, then “Source Keys”. Select the source key you are using and click “Edit”. Click “Edit Customization to Epay Form”.
- Insert this code into the document head:
<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>";
return false;
}
}
</script>
- You can make as many fields required as you want. To make a field required, repeat this section of code:
- if (document.epayform.UMfield.value=="") {
themessage = themessage + "<li> Name of Field</li>";
}
- Create inline instructions
- Find
<tr><
<td bgcolor="#F0F0F0" width="692" colspan="2"> </td>
- Replace it with
- <tr>
<td bgcolor="#F0F0F0" width="692" colspan="2" align="center">
<div id="required"><font size="2" face="Verdana" color="#ff0000">*</font><font size="2" face="Verdana"> indicates a required field.</font></div>
Create red *s
- Find
- <td bgcolor="#F0F0F0" width="450">
<input type="text" name="UMname" size="25" value="[UMname]"></td>
- Replace it with
- <td bgcolor="#F0F0F0" width="450">
<input type="text" name="UMname" size="25" value="[UMname]"> <font face="Verdana" size="2"color="#ff0000">*</font></td>
- Find
- <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>
<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>
- Replace it with
- <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>
<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>
- For every additional field, find
- <input type="text" name="UMfield" size="x" value="[UMfield]">
- Replace it with
- <input type="text" name="UMfield" size="x" value="[UMfield]"> <font face="Verdana" size="2"color="#ff0000">*</font>
Modify submit button
- Find
- <input type="submit" name="submitbutton" value="Process Payment >>">
- Replace it with
- <input type="submit" name="submitbutton" value="Process Payment >>" onclick="return verify();">
: