Gossamer Forum
Home : Products : DBMan : Customization :

If / Else statements erasing data

Quote Reply
If / Else statements erasing data
Hello
We are testing gossamer for online project management. Admin gets full access, Clients are limited to what fields they can edit when they click modify.

I had this working beautifully, but here is what happens.

Admin user signs in, adds project. And can modify no problem, all data stays in tact.
Clinet user signs in, with only view/modify permissions.

I used else/if statements (see below) to hide fields we don't want the customer to edit. These statements were used in the User Friendly HTML version in the "Record Layout" statement.
PROBLEM IS: When a client modifys a record, it deletes the data from all fields where else/if's are used. I checked raw db file too...data is gone.

Here is my else/if code below. Any ideas?

|;
if ($per_admin)
{
print "<input name=Designer type=TEXT id=Name value=$rec{'Designer'}>";
}
else
{
print "<i><font color=#666666 size=1 face=Verdana, Arial, Helvetica, sans-serif>this field is only editable by admin.</font></i>";
}
print qq|
POC Web Services - www.POC.us
Quote Reply
Re: [lostboy] If / Else statements erasing data In reply to
You need to add a hidden field to your "else" condition.

---------------------------------------------
else
{
print "<i><font color=#666666 size=1 face=Verdana, Arial, Helvetica, sans-serif>this field is only editable by admin.</font></i>";
print "<input name=Designer type=hidden id=Name value=$rec{'Designer'}>";
}
---------------------------------------------

The way DBMan works is that the entire record is rewritten when a record is modified, not just the fields that have been changed. Therefore, all of the fields have to be there. Fortunately, you can hide some. :-)


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] If / Else statements erasing data In reply to
Thanks I'll try that.
So you are saying that if the filed is hidden, the data wont get erased?
POC Web Services - www.POC.us
Quote Reply
Re: [lostboy] If / Else statements erasing data In reply to
Right. The hidden field will be populated with the current data from the record, but it won't appear on the screen and it won't be editable. When you hit the submit button, the value will be sent along with all the other values in the other fields.

You can see how it works by logging in as a non-admin and modifying a record. Take a look at the source code. You'll see the hidden fields with the information in them.

I don't know if you've seen my "Configurator," but it makes heavy use of hidden fields in order to maintain the selected values from one page to another. Also, if you use the autogenerate feature, you can set some fields to be hidden (by making their length -1) or "admin only" (by making their length -2). Hidden fields can be used in a lot of ways.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] If / Else statements erasing data In reply to
ah makes sense of course. your hidden field works *almost* perfect.
Now (last thing/promise) when modifying it will take a comnplete paragraph and delete all but 1 word.
so the data is there, but all but one word gets deleted in that field.
Here is a look at the else/ifs with your suggestion.

|;
if ($per_admin)
{
print "<textarea name=WebPageTitles cols=40 rows=5 wrap=VIRTUAL id=Description>$rec{'WebPageTitles'}</textarea>";
}
else
{
print "<i><font color=#666666 size=1 face=Verdana, Arial, Helvetica, sans-serif>this field is only editable by admin.</font></i>";
print "<input name=WebPageTitles type=hidden id=Name value=$rec{'WebPageTitles'}>";
}
print qq|
POC Web Services - www.POC.us
Quote Reply
Re: [lostboy] If / Else statements erasing data In reply to
All but one word? That's pretty strange.

It's likely that the problem has to do with the fact that your "normal" field is a textarea. I don't think I've ever come across that situation before.

Which word is kept? The first one? The last one? Is there something after the word, like a carriage return? Can you give me an example?


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] If / Else statements erasing data In reply to
yes, odd indeed.

If admin modifys, no problems.
If non-admin modifys, which uses else/ifs, then the problem occurs. But only in multi line text boxes. (note: removed virtual wrap and still does it)

Using the following paragraph for example;

when admin modifies/no problems:
Retail jewelry store with huge unique jewelry collection. Diamonds, Saphires, Runies and other colored stones.

when non-admin modifies, it ends up:

Retail
POC Web Services - www.POC.us
Quote Reply
Re: [lostboy] If / Else statements erasing data In reply to
You might try putting a MAXLENGTH attribute in the hidden field. I don't know if that's the problem or not.

Can you see the page source when you're on the modify page? I'd be interested to know if the full text shows up in the hidden field on the source or not. It would give a clue as to where the problem might be.

For the moment, the only thing I can think of is to change the textarea field to a regular text field. I know you don't want to do that, but I can't come up with another solution.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] If / Else statements erasing data In reply to
just tried single line text box...didnt work either.

I checked source when non-admin goes to modify, the whole paragraph is there, as soon as you modify the record, it trims to that first word.

Looks like I may have to use seperate html files for clients.
POC Web Services - www.POC.us
Quote Reply
Re: [lostboy] If / Else statements erasing data In reply to
Quote:
as soon as you modify the record, it trims to that first word.


That is a major clue, actually.

Okay. I want to get this straight in my head. Tell me if I have anything wrong.

--When you have a regular text field for the admin and a hidden field for the non-admin, it works fine. (This is the part that I'm really not sure of.)

--When you start out with a textarea field for the admin and a hidden field for the non-admin, there's a problem.

--Changing the textarea to a regular text field doesn't make any difference.

There was something like this several years ago that I remember helping someone with. I just have a vague memory of the look of the source code in his page. Seems that we went around and around trying to work it out and it ended up being something extremely simple. But it may not be exactly the same problem you're having.

Do regular text fields work all right?


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] If / Else statements erasing data In reply to
ok answers below...


--When you have a regular text field for the admin and a hidden field for the non-admin, it works fine. (This is the part that I'm really not sure of.)
ANS: When admin modifies, everything stays. admin isn't getting hidden fields displayed. only deletes fields for non-admin and only fields which are hidden using else/ifs

--When you start out with a textarea field for the admin and a hidden field for the non-admin, there's a problem.
ANS: Yes. any fields I use the if/else statements including the hidden line, text gets deleted ONLY when modified by non-admin.

--Changing the textarea to a regular text field doesn't make any difference.
ANS: Correct. still deletes

--Do regular text fields work all right?
ANS: No still deletes.
Here is a test acct for you. pay particular attention to the data field titled "Web Page Navigation/Section Titles"
Try pasting a paragraph in there, then modify the record, and watch the paragraph amazingly disapear, except for the first word.
go to: http://www.poc.us/...ectmanagement/db.cgi
user: deni
pass: deni
let me know as soo as you test so I can de-activate the username
POC Web Services - www.POC.us
Quote Reply
Re: [lostboy] If / Else statements erasing data In reply to
I think I've got it. If this is it, I told you it was something simple.

Instead of

print "<input name=WebPageTitles type=hidden id=Name value=$rec{'WebPageTitles'}>";


try

print qq|<input name=WebPageTitles type=hidden id=Name value="$rec{'WebPageTitles'}">|;

I think you need quotation marks around the actual value of a hidden field, especially if it's more than one word.

Sorry. I'm still a bit rusty. I don't work with DBMan nearly as much as I used to.

I did test it out. Thank you.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] If / Else statements erasing data In reply to
ooh, nice, that worked.
heh, something simple indeed.
Yea we don't use DBman much, as my programmer prefers php/MySQL.
This is an internal project though, and I am doing it, and am an old school programmer. I shouldn't really be programming actually, should be selling.
Anyway. thanks a million!
Rick aka LostBoy
POC Web Services - www.POC.us