Jimmy
|
| Posted: 08/12/2005, 10:44 AM |
|
New to CCS and php with a simple questions.
Test table with 3 simple field:
autokey, field1 and field2.
My question is how do I manually assign value to field2.
I use a record wizard to buid the Add/Edit for the record. I change field2 to label. Then I add code to the onclick button (submit) as follow:
global $Test;
$Test->field2->SetValue(($Test->field1)+3);
doesn't look like the code I put in had any effect. The field2 always blank no matter what value I put on field1. Did I do something wrong? I also try to insert the code to before update and it still did nothing.
|
|
|
 |
peterr
Posts: 5971
|
| Posted: 08/12/2005, 11:41 AM |
|
If you like to assign a visible value so that users see on the page, then please place your code in the Before Show event (of the form or the control).
If you like to change or overwrite user's entry (control value) after the record is submitted but before it is saved into the database, then you can use the Before Build Update event (and/or Before Build Insert for new records) to modify the datasource, like:
global $Test;
$Test->ds->field2->SetValue(($Test->ds->field1->GetValue())+3);
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
 |
 |
Jimmy
|
| Posted: 08/12/2005, 2:15 PM |
|
I put the code both on before show and Before Build Update event. It still does nothing at all. How do I debug it?
function Test1_ds_BeforeBuildUpdate()
{
$Test1_ds_BeforeBuildUpdate = true;
//End Test1_ds_BeforeBuildUpdate
//Custom Code @26-F35969ED
// -------------------------
global $Test1;
// Write your own code here.
$Test1->ds->field2->SetValue(($Test1->ds->field1->GetValue())+3);
// -------------------------
//End Custom Code
Please help.
|
|
|
 |
peterr
Posts: 5971
|
| Posted: 08/12/2005, 2:25 PM |
|
The above code can only work in Before Build Update/Insert. Before Show wouldn't need the "ds->". I also didn't realize that you use 2 different fields, so please use Before Show event of the form, not of the control.
To debug, just output/echo the values, like:
echo $Test1->ds->field1->GetValue());
echo $Test1->ds->field2->GetValue());
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
 |
 |
Jimmy
|
| Posted: 08/12/2005, 2:44 PM |
|
Thank for the quick respond.
1. I delete the code from before show.
2. I put in the echo statement in before show and both value come out.
3. I put the echo statement in the before build update but nothing is showing up.
4. I change the statement to
function Test1_ds_BeforeBuildUpdate()
{
$Test1_ds_BeforeBuildUpdate = true;
//End Test1_ds_BeforeBuildUpdate
//Custom Code @26-F35969ED
// -------------------------
global $Test1;
// Write your own code here.
$Test1->ds->field2->SetValue(1234);
// -------------------------
//End Custom Code
the field2 is always 0.
Please help.
Thanks, Jimmy
|
|
|
 |
Jimmy
|
| Posted: 08/12/2005, 2:54 PM |
|
Peterr,
Thank for your your help. I find out what is wrong now. My field2 is a label. Once I change the field from label to text or hidden. The code work fine.
Thank you very much.
Jimmy
|
|
|
 |
Damian Hupfeld
|
| Posted: 08/14/2005, 4:13 AM |
|
All new users should take note of that point -
If you need to use the value of one field on your page in another field then
it needs to be a text or hidden text field. This had caught me out so many
times!
regards
Damian
"Jimmy" <Jimmy@forum.codecharge> wrote in message
news:542fd1a7a03b4c@news.codecharge.com...
> Peterr,
>
> Thank for your your help. I find out what is wrong now. My field2 is a
> label.
> Once I change the field from label to text or hidden. The code work fine.
>
> Thank you very much.
>
> Jimmy
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
 |