Forums

Form to update Contact Details

bepos 14 Apr, 2009
Hi,

i've searched the forums but couldn't the right answer.

I'm building a form to update the contact details of the logged in user.

Here's the code so far :

<?php
$db =& JFactory::getDBO();
$query = 'SELECT * FROM #__contact_details WHERE id = 1';
$db->setQuery( $query );
$c_rows = $db->loadObjectList();
$c_name = $c_rows[0]->name;
$c_position = $c_rows[0]->con_position;
$c_address = $c_rows[0]->address;
?>

<div class="contentheading">edit contact</div>

<table class="cf_formtable">

<tr><td>Naam</td><td><?php echo $c_name; ?></td>
</tr>
<tr>
<td id="cf_label">Positie</td>
<td id="cf_input"><input name="con_position" type="text" class="inputbox" id="con_position" value="<?php echo $c_rows[0]->con_position; ?>">
</td></tr>

<tr>
<td id="cf_label">Beveiligingscode</td>
<td id="cf_input">{imageverification}

<a onclick="return false;" class="tooltiplink"><img  src="components/com_chronocontact/css/images/tooltip.png" class="tooltipimg" width="16" border="0" height="16"></a>
<div  class="tooltipdiv">Let op!: :: Beveiliginscode is hoofdlettergevoelig</div>

</td>
</tr>

<tr>
<td id="cf_label"> </td>
<td id="cf_input"><input id="cf_verzend" type="submit" name="cf_nm_verzend" value="Versturen" class="button"/></td>
</tr>

</table>


Now i would like to be able to update the data and store it in the same record. In this case the field con_position

I've read something to use $_POST, but i don't know how to 😟

anyone has any ideas.

Kind Regards,

Mark
GreyHead 14 Apr, 2009
Hi bepos,

If you use the DB Connectivity tab to connect the form to #__contact_details then it should update with any new values OK. You will need to make sure that you have the record id in the results - use a hidden field for this and you may need to hold other record info as well (I can't recall exactly how Joomla does the update).

Bob
bepos 14 Apr, 2009
Hi Bob,

thanx! the record id and the hidden field did it.
I also added the JFactory::getUser(); for the right userid.

only one thing : i had to enable the "Email the results" to update the fields. Is this really necessary?

here's the form code so far :


<?php
$db =& JFactory::getDBO();
$userInfo =& JFactory::getUser();
$userInfoId = $userInfo->id;
$query = 'SELECT * FROM #__contact_details WHERE user_id = '.$userInfoId;
$db->setQuery( $query );
$c_rows = $db->loadObjectList();
$c_id = $c_rows[0]->id;
$c_name = $c_rows[0]->name;
$c_position = $c_rows[0]->con_position;
$c_address = $c_rows[0]->address;
$c_postcode = $c_rows[0]->postcode;
$c_suburb = $c_rows[0]->suburb;
$c_email_to = $c_rows[0]->email_to;
$c_mobile = $c_rows[0]->mobile;
?>

<div class="contentheading">edit contact</div>

<?php echo $userInfoId; ?>
<table class="cf_formtable">

<tr><td>Naam</td><td><?php echo $c_name; ?></td>
</tr>
<tr>
<td id="cf_label">Positie</td>
<td id="cf_input"><input name="con_position" type="text" class="inputbox" id="con_position" value="<?php echo $c_rows[0]->con_position; ?>">
</td></tr>

<tr>
<td id="cf_label">Beveiligingscode</td>
<td id="cf_input">{imageverification}

<a onclick="return false;" class="tooltiplink"><img  src="components/com_chronocontact/css/images/tooltip.png" class="tooltipimg" width="16" border="0" height="16"></a>
<div  class="tooltipdiv">Let op!: :: Beveiliginscode is hoofdlettergevoelig</div>

</td>
</tr>

<tr>
<td id="cf_label"> </td>
<td id="cf_input">
<input id="cf_verzend" type="submit" name="cf_nm_verzend" value="Versturen" class="button"/>

<input type="hidden" name="id" value="<?php echo $c_rows[0]->id; ?>" />

</td>
</tr>

</table>


Kind regards,

Mark
bepos 14 Apr, 2009
Hi Bob,

well my form is working. i did some modifications in chronoforms 3.1RC4.11 and added two language files English and Dutch.

Attached you'll find al the files including an example form.

Kind regards and keep up the good work with Chronoforms!!!

Mark
GreyHead 14 Apr, 2009
Hi bepos,

The OnSubmit Before code only runs if Emails are ON. You can put the same code in the OnSubmit After if you have problems with the email setting.

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