This topic is locked

Edit once only

10/23/2006 6:37:09 AM
PHPRunner General questions
M
mmponline author

I need to set a specific field to be editible only the first time the record is edited. All fileds will be changeble, except the specific field where a closing date must be entered. Once the date has been set and record saved, the user must not be able to change the date himself again - must become read only. Changes wil have to be forwarded to admin for changes.
If possible, admin must be able to "activate" the field again so that the user will be able to edit the specific field once -again.
Thanks for any suggestions.

T
thesofa 10/23/2006

it seems that this has been partly answered by this post here

M
mmponline author 10/23/2006

thesofa
This is not really what I need.

  1. I create a record in admin that is activated for user by the refno.
  2. User logs in and then needs to complete the record with other information - Including the ClosingDate field.
  3. On return to the field to edit again, all fileds must be editible again, except the ClosingDate field (Needs to be readonly.

Sergey Kornilov admin 10/23/2006

Stephan,
you can do something like this:

  1. Add a new field that holds a number of times this record was edited.

    Default value in the database should be set to 0.
  2. Use BeforeEdit or AfterEdit event to increment this field.
  3. Modify edit page to make this field readonly if record was edited one or more times.

    Something like this will work:

if ($data["NumberOfEdits"]>0)

{

echo "<script>document.editform.value_ClosingDate.disabled=true;</script>";

}


To enable this field to be edited again admin can set NumberOfEdits value to 0.

M
mmponline author 10/24/2006

Seems like I'm missing somethng, somewhere.
Your logic makes sence, but does not work.

  1. I creatd a NumberOfEdits field - default 0
  2. I copied your code into the events page:
    Sample:

    function AfterEdit()
    if ($data["NumberOfEdits"]>0)
    {
    echo "<script>document.editform.value_ClosingDate.disabled=true;</script>";

    }
    Using this I get a parse error:

    Parse error: parse error, unexpected T_IF, expecting '{' in /usr/www/users/govade/govademploy/include/Opportunities_events.php on line 5
    I tried the code moving the {

    Sample:

    function AfterEdit()

    {

    if ($data["NumberOfEdits"]>0)
    echo "<script>document.editform.value_ClosingDate.disabled=true;</script>";

    }
    No error message, but function does not work.
    Now I'm stuck. Please assist!

J
Jane 10/24/2006

Stephan,
you need to place your code to the EditOnLoad event, not to the AfterAEdit event.

Here is a sample code:

function EditOnLoad()

{

global $where;

global $data;

echo "<script language=javascript>document.editform.value_ShipName.disabled=true;</script>";

}



Also you need to move OnLoad event on the bottom of the Edit page on the Visual Editor tab.
In the BeforeEdit event you can increment value of NumberOfEdits field:

function BeforeEdit(&$values, $where)

{

$values["NumberOfEdits"]++;

return true;

}

M
mmponline author 10/24/2006

Jane
I've done as explained, moving the Onload event to the bottom of the page. It only produce some results:

  1. The date is readonly on entering edit page. This is irrespective whether the NumberOfedits filed is set to 0,1 or any other value. It should be readonly when 1 or greater.
  2. When saving the edit page, the date is removed competely and the field is left empty. Shold not be.
  3. The NumberOfEdits only changes fron 0 to 1 and not 2,3, 4 on saving edit page again.

    ??

Sergey Kornilov admin 10/24/2006

Stephan,
it's impossible to tell you what is wrong because I don't have your files.
I recommend you take baby steps.

  1. Make sure NumberOfEdits field is incremented on every edit.
  2. Make sure you put code that disables closingdate field in correct place. See my post again. You need to put at the end of file. Do not put it into Events.

M
mmponline author 10/31/2006

Sergey
Sorry for coming back on this after so long. I had to make progress on this project, thus leaving this aside for a while. Well, now I'm back, expriencing the same problems:

  1. The NumberofEdits field increments from 0 to 1, and not further.
  2. When I move the OnLoad event to the bottom of the page, the date field is readonly whether NumberOfEdits is 0 or 1.
  3. When I save the record, the date is removed from the Closingdate field completely.
    Help!

Alexey admin 11/1/2006

Stephan,
I suppose you need to debug your code to get it working properly.

You can try to do this by your own or hire a programmer.
You need to know PHP to do this by your own.

Here are some good links to start learning PHP.
http://www.w3schools.com/php/default.asp

http://www.webcheatsheet.com

http://www.php.net

M
mmponline author 11/1/2006

IOW, the code that you supplied is incorrect. Pitty I did not know this from start as I spent a lot of time on this, trying to debug it from the code you supplied.
Is there any other suggestions from the forum?
I'll have a look at these sites asap. Thanks for that.

M
MikeB941 10/21/2007

Dear Jane:
This is such a terrific piece of code (the javascript you provided to conditionally disable a field)!
I've used it without a hitch on everything but DATE fields?
Every other kind of field can be conditionally disabled in the EditOnLoad event and works perfectly (the field disables, the background color changes to indicate that it's disabled AND the data is preserved after the SAVE button is clicked on the edit page).
For some reason on DATE fields two things happen:

  1. If you're using the drop down boxes or the date picker the disable is ignored (I can live with this, because if you change the date type to a simple edit box the disable is observed - however it would be GREAT if the disable would also freeze the drop down boxes and the date picker.
  2. This is the BIG PROBLEM - for some reason the DATE GETS CLEARED when a date field that's been disabled is saved as part of the edit record update. I've read various posts about setting the disable field back to FALSE to avoid this but I've never had to do that for any other type of field AND even if I reset the disabled DATE field to FALSE in the Before Record Update event it seems to be too late to do any good (there is a post about using a Java script on the SAVE button to reset the disabled field back to FALSE and maybe it has to be done there...
    ANYWAY, would sure appreciate some more of your brilliance on this one! Like I said this works GREAT for every field type except dates (I just conditionally set any field I want such as document.editform.value_UP_LoanOutInfo.disabled=true; in EditOnLoad and it works like a charm! Now if I could just getting it working for the date fields as well that would be TERRIFIC!
    Thanks again Jane!!!
    Take Care... Mike.