Welcome to the nuBuilder Forums!

Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.

Before Save validation

Questions related to using nuBuilder Forte.
Post Reply
ricklincs
Posts: 121
Joined: Mon Aug 01, 2011 5:39 pm
Has thanked: 41 times

Before Save validation

Unread post 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?
kev1n
nuBuilder Team
Posts: 4581
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 76 times
Been thanked: 536 times
Contact:

Re: Before Save validation

Unread post 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.
Post Reply