Update fields with PHP session variables

Update fields with PHP session variables

razethrazeth Posts: 4Questions: 2Answers: 0

Hello!

I want to create a system to track when a record is created and modified. I have created all of the fields needed and made them read only so they can't be changed, I just can't seem to figure out the rest.

I'm using a ON UPDATE CURRENT_TIMESTAMP attribute for lastmodified, however I still need some way to handle the other three options.

I need to pass $_SESSION["username"] to the field createdby and the current time to createdat when a new entry is submitted.

I also need to pass $_SESSION["username"] to the field modifiedby whenever a change is made to a field.

Any suggestions on how this can be done easily?

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Is this using Editor? If so, you can use client-side events or server-side events for that.

    Colin

  • razethrazeth Posts: 4Questions: 2Answers: 0

    @colin Yes it is using editor - I get using events but don't see what events i'd use to call this, especially if a user were to select and edit multiple fields.

    Any suggestions on what events specifically would work best for these situations? I figure they would all be client side as all the data needed to handle could be pulled and posted from the client side.

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Hi,

    The key here is to use the Field->setValue() method. It let's you specify a value that will be written to the db for that field - e.g.:

    Field::inst('createdBy')->setValue($_SESSION['username'])
    

    Regards,
    Allan

This discussion has been closed.