Forums

I need to add and clear numbers

U Can Drive 09 Jan, 2016
I have two forms.

StudentForm which has a Field called LessonsPaid which has the number of lessons a student has paid for.
and
VoucherForm which has a Field called VPaid which has the number of lessons on a voucher.

I have a form that loads up both forms above.

I want to:
1) add VPaid to LessonsPaid
2) Clear the VPaid field to 0
3) Save both forms (I can manage this part)

I suspect I will need to use PHP code in the Load JavaScript function in setup. Could someone please help me with the PHP code?

Thank you
GreyHead 09 Jan, 2016
Hi U Can Drive,

Yes you will need some custom code certainly some PHP after the form submits and possibly some JavaScript if you want to change the data in the browser.

Your specification here is rather vague but I'm guessing that what you need to to is this:

+ have a voucher input in the form and use Ajax to check the voucher validity and number of lessons when the voucher code is entered.

+ if the voucher is valid add the number of lessons to the LessonsPaid input.

These can be done with Custom JavaScript and a new form event with some PHP to check the voucher from the vouchers table.

After the form submits you should re-check the voucher validity to avoid any hacked entries; then mark the voucher as 'used' in the vouchers table - that needs a little PHP and a DB Save

Lastly save the Student record with the updated number of paid lessons using a second DB Save.

Bob
This topic is locked and no more replies can be posted.