[SOLVED] Create 2 Form with 1 Table

d3x73r 02 Sep, 2010
Hi...
I'm just starting to use ChronoForms. I just replaced Joomla registration to my custom registration form, but there is a question.
I need to create a form that is avalible only when user is registered. Once he register he can fill the new form. The problem is that i need to update de table, and not create a new record.
Is there any way to do this?

Thanks!
GreyHead 02 Sep, 2010
Hi d3x73r,

Yes you can do this - search here for 'getUser' for many threads with the code to restrict form access.

To have your form update a record then the submitted data *must* include an existing primary key value for the table.

Bob
d3x73r 05 Oct, 2010
Hi Grey,
I'm tired to try here... I cant update my table.
I need to fetch this table and update a column. I tryed to get cf_id but don't know how.

Here is my code:

<?php
// Get user-information from Joomla
$user = &JFactory::getUser();
?>

<div class="form_item">
  <div class="form_element cf_heading">
    <h1 class="cf_text">Marcando Boleto Pago</h1>
  </div>
  <div class="cfclear"> </div>
</div>

<input type="text" name="id" id="id" value="<?= $user->id; ?>" />
<input type="text" name="username" id="username" size="20"
maxlength="40" value="<?= $user->name; ?>" />


<div class="form_item">
  <div class="form_element cf_radiobutton">
    <label class="cf_label" style="width: 150px;">Status</label>
    <div class="float_left">
      <input value="1" title="" class="radio validate-one-required" id="radio00" name="pago" type="radio" />
      <label for="radio00" class="radio_label">Pago</label>
      <br />
      
<input value="0" title="" class="radio validate-one-required" id="radio01" name="pago" type="radio" />
      <label for="radio01" class="radio_label">Não</label>
      <br />
      

    </div>
    
  </div>
  <div class="cfclear"> </div>
</div>
<div class="form_item">
    <input value="Enviar" name="button_15" type="submit" /><input type="reset" name="reset" value="Reset"/>
  <div class="cfclear"> </div>
</div>


Thanks for your help!
GreyHead 05 Oct, 2010
Hi d3x73r ,

What table are you trying to update? We need more specific information to help.

Bob
d3x73r 05 Oct, 2010
Sorry, the table is: jouefs10_chronoforms_usuarios
I'm using this in order to joomla registration, with more informations. Once the user have registered, he have to fill another form, just checking a box. Then i need to update this information about that user.
When i fill the form, it creates another roll.

Here is the generated code:

<?php
        $MyForm =& CFChronoForm::getInstance("pagamento");
        if($MyForm->formparams("dbconnection") == "Yes"){
            $user = JFactory::getUser();            
            $row =& JTable::getInstance("chronoforms_usuarios", "Table");
            srand((double)microtime()*10000);
            $inum    =    "I" . substr(base64_encode(md5(rand())), 0, 16).md5(uniqid(mt_rand(), true));
            JRequest::setVar( "recordtime", JRequest::getVar( "recordtime", date("Y-m-d")." - ".date("H:i:s"), "post", "string", "" ));
            JRequest::setVar( "ipaddress", JRequest::getVar( "ipaddress", $_SERVER["REMOTE_ADDR"], "post", "string", "" ));
            JRequest::setVar( "uid", JRequest::getVar( "uid", $inum, "post", "string", "" ));
            JRequest::setVar( "cf_user_id", JRequest::getVar( "cf_user_id", $user->id, "post", "int", "" ));
            $post = JRequest::get( "post" , JREQUEST_ALLOWRAW );            
            if (!$row->bind( $post )) {
                JError::raiseWarning(100, $row->getError());
            }                
            if (!$row->store()) {
                JError::raiseWarning(100, $row->getError());
            }
            $MyForm->tablerow["jouefs10_chronoforms_usuarios"] = $row;
        }
        ?>
        
GreyHead 05 Oct, 2010
Hi d3x73r,

I must write this up properly - it's been on the to-do list for a while.

Here's the short answer.

Add this code in the OnSubmit Before box (make sure that "Send Emails" is set to 'Yes' on the General tab even if you aren't sending any).
<?php
$user =& JFactory::getUser();
$db =& JFactory::getDBO();
$query = "
    SELECT `cf_id`
        FROM `#__chronoforms_usuarios`
        WHERE `cf_user_id` = '".$user->id."' ;
";
$db->setQuery($query);
$cf_id = $db->loadResult();
JRequest::setVar('cf_id', $cf_id);
?>
I think that should do the trick.

Bob
d3x73r 05 Oct, 2010
Nice! It work perfectly!
Thanks!
This topic is locked and no more replies can be posted.