Gianni
|
| Posted: 03/20/2002, 8:26 AM |
|
Hi,
I'm using CC 2.05 eval. on a Win 98 PC.
The language used for my test project is PHP4 with templates.
I have a form of type "Record". In form properties I have checked
"Allow Insert" and "Allow Update". When form is displayed, only "Update"
button appears?
Where's "Insert" button?
TIA
Gianni
|
|
|
 |
Brent
|
| Posted: 03/20/2002, 8:44 AM |
|
Only the Update button appears for the Record form because you are editing the
record. You won't see both the Insert and Update buttons visible at one time
because you can only be Inserting or Updating a record (not both at the same
time). The Record Form goes into Update mode if you pass it the primary keys
and it finds the record. If it doesn't find the record (because the primary
keys weren't passed) the the Record form goes into Insert mode.
|
|
|
 |
Gianni
|
| Posted: 03/20/2002, 9:11 AM |
|
Thank you Brent. Your answer is very clear.
But I have a doubt.
How do I avoid passing the primary key?
This is the situation:
I have:
- one "Record" form with label fields only used for display
- one "Record" form with editable fields for updates and new insertion.
I would like to have on the display form:
- one "Update" button for editing the current record
- one "Insert" button for adding new records to the database.
Both buttons should link to the same editable form.
Can I do this and how? Or I'd better find another solution?
Gianni
|
|
|
 |
Brent
|
| Posted: 03/20/2002, 1:34 PM |
|
>>How do I avoid passing the primary key?
This is the situation:
I have:
- one "Record" form with label fields only used for display
- one "Record" form with editable fields for updates and new insertion.
I would like to have on the display form:
- one "Update" button for editing the current record
- one "Insert" button for adding new records to the database.
Both buttons should link to the same editable form.
Can I do this and how? Or I'd better find another solution?<<
Normally when you click on a record in a grid, it passes the primary fields
from that grid row to your record form, so the record form automatically goes
out and finds that record and puts the record into Update mode.
But if you press the INSERT button on the grid then it calls the same Record form but without the key fields
so it has nothing to look up and goes into Insert mode. This is all done automatically.
I only re-mention this because this is how we control whether the record form
is updating an exsting record or inserting a new record.
Ok, so I'd suggest having 2 forms on the same page. Your View Record form and your
Update/Insert record form. Your Update/Insert record form is of course 1 form that
handles updates or insert depending on whether it was passed the primary key fields or not
and a special parameter called "mode=U".
I suspect you want to display the View Record form by default which has 2 buttons
Insert, Update and these buttons if pressed will call up the Update/Insert record.
Correct?
Ok good.:) I assume you know how to hide forms. It was covered in another topic
a few months back (see below). Here is the logic involved to display either the
View or Update/Insert record form.
If the Record page is called from another page, it will automatically hide the
Update/Insert form and displays only the View form. It does this because it is
missing a parameter, let's call it "mode" and can have a value "V" for View or "U"
for Update/Insert. If this parameter is missing it goes into View Mode. So any
page that calls this record page won't have the "mode" parameter so it goes into View mode.
You can probably get rid of the Update,Insert,Delete buttons on the View record form
because I don't see them being of any use. You can replace it with your own menu form
that appears at the bottom of the View Form and has the buttons
Insert, Update, Delete that calls this same record page.
The Update button on this View Record form will pass the key field parameters along with
mode="U" and it calls this same page. Now the page has the mode="U" so it displays
the Update Record (and hides the View record) and it automatically calls up the record using the key field parameters
that were passed. The Insert button on the View record passes mode="U" but neglects
to pass the primary keys so the Update form goes into Insert mode.
It's reasonably simple to do.
Quick method of hiding forms.
In the Open event of the form that you're trying to hide:
//View Record Form Open Event
if (get_param("mode")=="U")) //If we are updating, hide the View form
{
$tpl->set_var("FormViewRecord",""); //Prefix "Form" to your form name "ViewRecord"
return;
}
//Update Record Form Open Event
if (get_param("mode")!="U")) //If we are not updating, hide the update form
{
$tpl->set_var("FormUpdateRecord",""); //Prefix "Form" to your form name "UpdateRecord"
return;
}
All of this code is off the top of my head. If it doesn't work, blame my
barber.<g>
|
|
|
 |
Gianni
|
| Posted: 03/21/2002, 1:33 AM |
|
Brent, thank you very much.
That's still too complicated for me. I've been using this product for
just 10 days and I have a lot to learn.
I can resolve the problem using the insert function of the grid form; it's
simpler and I don't have to write any code. This will allow me to painless
switch from PHP to JSP if I need it. And it might be the case because with
JSP I can use the IBM DB2 database driver, not available when I choose PHP.
It would be great if I could run complex dynamic page without coding.
I wish CodeCharge is going toward this direction.
Best wishes.
Gianni
|
|
|
 |
|