Forums

Edit a profile

robo2000 28 Jan, 2010
I have created a substantial form using Chronoforms and the input and viewing of the information in an editable format is working great just using the form code section. When a record is edited, and that information is posted to the dbase it is creating a new record and not editing the old record. I thought I had made this change to the php but obviously not. Can anyone see what I need to do to the code to post to the current record. Individual logged in.

Andrew
    <?php
    $user =& JFactory::getUser();
    if ($user->id == 0)
    {
    //User not logged in, stop loading the form...
      echo "You are not allowed to access this page. Please login first!";
      return;
    }

    //Get an instance of the JDatabase object...
    $db =& JFactory::getDBO();

    //Build the SQL-query...
    $query = sprintf('SELECT * FROM %s WHERE %s = %d LIMIT 1',
      $db->nameQuote('jos_hive_profile'),
      $db->nameQuote('cf_user_id'),
      $user->id
    );
    //... load it, and get the result..
    $db->setQuery($query);
    $userData = $db->loadObject();

    //Get the session storage, we'll need this to keep track of which database record we're editing:
    $sess =& JFactory::getSession();
    $sess->set('cf_id', $userData->cf_id, md5('chrono'));

    //Now we've got all the data, proceed to the actual form:
    ?>
<?
$sess = JFactory::getSession();
$cf_id =& $sess->get('cf_id', 0, md5('chrono'));
JRequest::setVar('cf_id', $cf_id);
?>		
GreyHead 29 Jan, 2010
Hi Andrew,

Instead of adding the cf_id to the session put it into a hidden field in the form
<input type='hidden' name='cf_id' value='<?php echo $userData->cf_id; ?>' />

Bob
robo2000 29 Jan, 2010
Absolutely spot on thanks for this, has worked successfully.

Chronoforms is fantastic

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