TOPIC:

Where to add custom script in BF Interface? 9 years 2 weeks ago #81976

  • Topic Author
  • comptweb
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 27
  • Thanks: 0
Hello again,

I am looking to add a script that will validate one field but having issues getting it to function properly as I am not exactly sure where to insert it.

What the script is meant to do: It is a script that checks to make sure the number entered into the field is valid (check digit). It is "similar" mod 10 numbering.

The code is as follows:

/*================================================================================================*/

/*

This routine checks a ticket number. The following checks are made:

1. The number is 7 digit (7th is the check digit)
2. The number has a valid modulus 10 "like" value for the first six digits that equals the ckeck digit

*/

/*
If a number is invalid, an error reason is loaded into the global ccErrorNo variable.
This can be be used to index into the global error string array to report the reason to the user
if required:

e.g. if (!TicketValidation (number) alert (ccErrors(ccErrorNo);
*/

var ccErrorNo = 0;
var ccErrors = new Array ()

ccErrors [1] = "No Number provided";
ccErrors [2] = "Number is not 7 digits";
ccErrors [3] = "Number is in invalid format";


function TicketValidation (ticknumber) {

// Ensure that the user has provided a ticket number
if (ticknumber.length == 0) {
ccErrorNo = 1;
return false;
}

// Now remove any spaces from the ticket number
ticknumber = ticknumber.replace (/\s/g, "");

// Ensure that the user entered the right number of digits
if (ticknumber.length != 7) {
ccErrorNo = 2;
return false;
};

// Check that the number is numeric
var tickno = ticknumber
var tickexp = /^[0-9]{13,19}$/;
if (!tickexp.exec(tickno)) {
ccErrorNo = 3;
return false;
}

// Now generate a checksum value
{
var checksum = 0; // running checksum total
var mychar = ""; // next char to process
var j = 1; // takes value of 1 or 2
var cd = tickno.charAt(tickno.length - 1); // isolate the check digit

// Process each digit one by one starting at the left (skip the check digit)
var calc;
for (i = 0; i <= 5; i++) {

// Extract the next digit and multiply by 1 or 2 on alternative digits.
calc = Number(tickno.charAt(i)) * j;

// Add the units element to the checksum total
checksum = checksum + (calc % 10);

// Switch the value of j
if (j ==1) {j = 2} else {j = 1};
}

// All done - Now compare the units element of the checksum against the check digit
// If not, report an error.
if (checksum % 10 != Number(cd)) {
ccErrorNo = 3;
return false;
}
}

// The ticket number is in the required format.
return true;
}

/*================================================================================================*/

Any assistance would be greatly appreciated.

Please Log in or Create an account to join the conversation.

Re: Where to add custom script in BF Interface? 9 years 2 weeks ago #82102

  • djhargrove's Avatar
  • djhargrove
  • Offline
  • Ultimate Breezer
  • Ultimate Breezer
  • Official Support
  • Posts: 3419
  • Thanks: 222
I logged into you
Site but I don’t see a paypal button at all did you remove it?

Please Log in or Create an account to join the conversation.

Re: Where to add custom script in BF Interface? 9 years 2 weeks ago #82105

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 10064
  • Karma: 167
  • Thanks: 808
Hi,

I created you a validation package that implements your code.
Please download the attachment, unzip and install in BF => Configuration => Package Installer.

In your form, go to the field's validation, choose "library" and select "bf_ticket_validation".

I cannot tell about the algorithm you are using there (always was wrong), but if you have a look at Scripts Manager => package "BF" => Ticket Validation, you can see how to edit the code of your validation.

Regards,
Markus
Attachments:

Please Log in or Create an account to join the conversation.

Re: Where to add custom script in BF Interface? 9 years 2 weeks ago #82114

  • Topic Author
  • comptweb
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 27
  • Thanks: 0
I have it installed and it shows in the pulldown menu.
Just waiting for the guy who is building the form to test it.

Please Log in or Create an account to join the conversation.

Re: Where to add custom script in BF Interface? 9 years 2 weeks ago #82116

  • Topic Author
  • comptweb
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 27
  • Thanks: 0
Were you getting it to error?

It is letting me submit with any 7 numbers in the field.

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.049 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

September Discount!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!