Forums

Override "cf_user_id" on Front-End Post

coffeej 11 Jan, 2010
I am trying to create a Front-End connection that will allow an admin to view records and make some minor edits to a single table. I am successfull at displaying them and modifying the edit-links and subsequent SQL queries with URL parameters to fetch the correct records. However, whenever the record is updated and submitted, CF automatically posts the current user's ID into the cf_user_id field. I would like the field to remain unaffected - since I really want the original user's id left there.

Is there something I can put in the OnSubmit Code or elsewhere that can override the posting of cf_user_id? If I change the order and process the OnSubmit code after the Auto-Generated code, I figured I might be able to get around this problem, but am not sure what the PHP might be - or if it would even work.

PS: I'm trying to avoid the backend admin, since it does not perform the Javascript field input masks that I'm using for phone numbers, zip code, etc.

Thanks for your input in advance...
GreyHead 11 Jan, 2010
Hi coffeej,

Make sure that you set the value of cf_user_id in a hidden input in the form html. ChronoForms will use a value returned from the form if there is one, if there isn't it will use the current user id.

Bob
coffeej 18 Jan, 2010
Thanks GreyHead... that worked perfectly.

At first, I received a "row edit error" using my own link like: "http://sitename.org/index.php?option=com_chronoconnectivity&connectionname=ConnectionName&task=editrecord&mids={field1}&mmids={field2}&cids={field3}" (I'm using the URL parameters to send values to the form in hidden fields as you described) However, if I included the Chronoforms {edit_record} in a DIV with style="display:none;" for some reason, my link works. Somehow including the Chronoforms link causes the editing permissions to be OK?

Oh well, discovered by accident and it works.
Jetsfan 26 Mar, 2010
by an accident, i changed cf_user_id into "uniqe" Is this a problem? Till now everything works fine.
GreyHead 27 Mar, 2010
Hi Jetsfan,

If you've changed it consistently and it's working OK then it's probably OK.

Bob
ajlinn 01 Jun, 2010
Hi, Having the same problem... didn't want the special user with edit privileges on the table to override the cf_user_id. I added the cf_user_id and set it to {cf_user_id} which works fine for the issue chronoconnectivity edit issue, but now when I add/create a new record via the original form the cf_user_id is set to zero!

If the answer is already in the posts & forms, please provide a link as I wasn't able to find it.
Also please note that I'm a newbe to both ChronoEngine and PHP. The more detail the better for me.

Kind Regards
Alan
GreyHead 03 Jun, 2010
Hi ajlinn,

I still think this is probably the right answer

Make sure that you set the value of cf_user_id in a hidden input in the form html. ChronoForms will use a value returned from the form if there is one, if there isn't it will use the current user id.



Bob
ajlinn 22 Jun, 2010
Hey Greyhead,

I've no doubt your right ... I persisted with it for a bit longer ... but couldn't get it to work ... I added the below code In chronoforms - Form Code (tab) Form HTML:(May contain PHP code with tags) section.
<?php

  error_reporting(0);

  if ($_GET["task"] == "editrecord")
  {
     echo "Working in Edit mode:";
     echo "<input value={cf_user_id} id='cf_user_id' name='cf_user_id' type='hidden' />";
  }
  
?>



hope this helps someone else.
Thjanks for hte help I'm sure I'll have many more questions as I'm only getting started with chronoforms and chronoconnectivity - as it looks great.
avandakey 03 Jul, 2011
Yeah, this helped me out a lot. I'm still trying to get the hang of PHP coding and this made my life much easier.
Psoriasis Relief
GreyHead 03 Jul, 2011
Hi Alan,

First off, I rand into this problem recently and dicided that I would simply add a new column to that table for the user_id that is separate from the cf_user_id. That gets round the problem you have of trying to protect the cf_user_id value. That column is there to show who last updated the record, not especially to store the user id.

For your code example: You usually can't mix the ChronoForms curly bracket {input_name} syntax and PHP. In this case stay with the PHP
<?php
error_reporting(0);
$task = JRequest::getString('task', '', 'get');
$cf_id = JRequest::getInt('cf_id', '', 'get');
if ( $task != 'editrecord' || !$cf_id ) {
return;
}
// you have to get the value of cf_user_id
$db =& JFactory::getDBO();
$query = "
  SELECT `cf_user_id`
    FROM `#__some_table`
    WHERE `cf_id` = '$cf_id' ;
";
$cf_user_id = $db->loadResult();
echo "Working in Edit mode:";
echo "<input value='{$cf_user_id}' id='cf_user_id' name='cf_user_id' type='hidden' />";
?>

Bob
This topic is locked and no more replies can be posted.