Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

Validate server side

Locked
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Validate server side

Unread post by massiws »

I have this code in Custom Code > Javascript:

Code: Select all

var todo   = document.getElementById('app_todo').value;
 var hstart = document.getElementById('app_hstart').value;
 var hend   = document.getElementById('app_hend').value;
 if (todo && hstart && hend) {
     document.getElementById(fieldName).value = '1504a5e1ca9115';
 }
The code is executed and I can see the app_aps_id changing value.

Then I insert this in Before Save to check data server side:

Code: Select all

define("DA_FATTURARE","1504a5e1ca9115");

$todo   = $_POST["app_todo"];
$hstart = $_POST["app_hstart"];
$hend   = $_POST["app_hend"];

if (($todo != '') && ($hstart != '') && ($hend != '')) {
    $_POST["app_aps_id"] = DA_FATTURARE;
}
But after record is saved the new value is ignored.

Maybe I missed something?
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: Validate server side

Unread post by admin »

massiws,

Try this..

Code: Select all

         document.getElementById(fieldName).value = '1504a5e1ca9115';
         uDB(document.getElementById(fieldName));
A field won't be saved if nuBuilder doesn't know its been updated.

http://wiki.nubuilder.com/tiki-index.ph ... _pElement_

Hope this helps.

Steven
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: Validate server side

Unread post by massiws »

Steven,

thanks a lot, this fix the problem!

But what happen if a user disable the JavaScript on his client, the server side validation must work, isn't it?
How can I check and change the field values before the record is saved?
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: Validate server side

Unread post by admin »

massiws,

You will need to handle this manually in Before Save or After Save

Steven
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: Validate server side

Unread post by massiws »

Steven,
admin wrote: You will need to handle this manually in Before Save or After Save
that's what I've done:
massiws wrote:Then I insert this in Before Save to check data server side:

Code: Select all
define("DA_FATTURARE","1504a5e1ca9115");

$todo = $_POST["app_todo"];
$hstart = $_POST["app_hstart"];
$hend = $_POST["app_hend"];

if (($todo != '') && ($hstart != '') && ($hend != '')) {
$_POST["app_aps_id"] = DA_FATTURARE;
}

Also without the uDB() function in Javascript, this code in Before Save should work...
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: Validate server side

Unread post by admin »

.
Locked