Page 1 of 1

Before Save validation

Posted: Mon Oct 06, 2025 5:10 pm
by ricklincs
I would like to before saving my vehiclein form (field reg_no} to check that a record in vehiclestk (field stk_reg_no) doesn't already exist with the same reg_no and if it does the record should not be saved and an Alert is shown saying 'Duplicate Reg No not allowed'.

I already check following with js in browse and edit:

Code: Select all

window.nuBeforeSave = function() {
    var vehicleType = nuGetValue("vehicle_select");  // Get value from the "vehicle_select" field
    var trlContainerNo = nuGetValue("trl_container_no").trim();  // Get value from "trl_container_no"

    if ((vehicleType === "Truck & Trailer" || vehicleType === "Truck & Container") && trlContainerNo === "") {
        alert("Trailer/Container Number is required when selecting 'Truck & Trailer' or 'Truck & Container'");
        return false;
    }

    if ((vehicleType === "Truck Only" || vehicleType === "Car") && trlContainerNo !== "") {
        alert("Trailer/Container Number must be blank for 'Truck Only' or 'Car'.");
        return false;
    }

    return true; // Allows form save if all conditions are met
};
Is there a way I can add this to the above or should I run a php query to do a count in Before Save? with a nuDisplayError if the count is not equal to 0?

Re: Before Save validation

Posted: Tue Oct 07, 2025 11:06 am
by kev1n
If you need to retrieve information from other tables, database records, or related data, you’ll need to use PHP to run a database query. The best place to do this is in the Before Save PHP event, where you can execute your script, check conditions, and, if necessary, display an error message and stop the record from being saved.