Topic: Validate fields: sales_order_entry.php modification

Hi,

We want to ensure in our direct invoice entry that the customer branch and dimension selected by the users match. This is very crucial for our set up as we do not want users posting wrongly.

Here is the code i have included in the sale_order_entry.php file.

if (get_post ('branch_id') != get_post('dimension_id'))
{
           display_error(_("The branch does not match the dimension chosen."));
           set_focus ('dimension_id');
           return false;
}

The problem is that the dimension field options contains the IDs of the dimensions themselves. e.g. 1 Brisbane, 2 London etc. while the branches are Brisbane, London etc.

So every time an entry is made, the error "The branch does not match the dimension chosen." appears because of the number IDs that appear with the dimensions. i have tried the substr() but have not had luck.


Please i need help in ensuring that these two fields match and the effective way to do that is to warn the user before the invoice is posted.

Help is urgently needed. Thanks.

Re: Validate fields: sales_order_entry.php modification

If it's just a number followed by a space followed by the string you want to match, I would suggest a regex.

Substr() will fail when you get more than 9 (or 99 and so on) branches/dimensions, and the branch name moves further right in the string.

So just strip off something like [0-9]+\s+ (any number of digits followed by any amount of whitespace) from the start of the dimension string before comparing it to the branch string.

Re: Validate fields: sales_order_entry.php modification

Hi,

Thanks for your reply. I have tried what you suggested but have not gotten a breakthrough yet. here is the piece of code i added, i'm not sure if i did the right thing;

}
    $match = get_post ('dimension_id');
    $match = preg_replace ('/^\d+\s+/', ' ', $match);
    if (get_post('branch_id') != $match)
    {
        display_error(_("The Branch does not match the Dimension chosen."));
        set_focus ('dimension_id');
        return false;
    }

please can someone check to see what i am not getting right with sample please. Thanks

Re: Validate fields: sales_order_entry.php modification

The obvious problem with that code is that you are replacing the matched section with a space, rather than an empty string.

Re: Validate fields: sales_order_entry.php modification

Hi tm,

I'm not really an expert in this stuff called php. I would appreciate if someone just corrected this code for me. Thanks. Want to ensure the branch chosen is the same with the dimension.

Re: Validate fields: sales_order_entry.php modification

Fair enough. Removing the space, your code becomes:

    $match = get_post ('dimension_id');
    $match = preg_replace ('/^\d+\s+/', '', $match);
    if (get_post('branch_id') != $match)
    {
        display_error(_("The Branch does not match the Dimension chosen."));
        set_focus ('dimension_id');
        return false;
    }

See if that works.

Re: Validate fields: sales_order_entry.php modification

Hi tm,

I see what you are trying to point out now. I actually tried that earlier and it did not work. I just copied your code and it still did not work.

I appreciate your help this far, but can you help me fix this for good pls?

Thanks

Re: Validate fields: sales_order_entry.php modification

Hi all,

I'm still working to solve this problem on my own. I used the var_dump() to investigate why the code above was not working and discovered that the obvious reasons why it did not work.

The $_POST array contained branch_id as an integer and the dimension_id was also an integer but with a different value from the branch_id. Invariably, there won't be a match.

My proposed solution is to compare the branch and dimension names (strings) within database instead of the id(s) by introducing hidden fields for the names within the form and matching them together.

My question is how do i make hidden fields within the direct invoice form in FA. I am previously used to html tags, it seems FA makes use of a different convention i am yet to fully understand. So pls i really need help on this.

Secondly, what other scripts will require modification for the solution to work?

Thanks.

Re: Validate fields: sales_order_entry.php modification

Instead of hidden names in the form, why not lookup the names from the db in the processing code?