Forums

single button that uses registered user information

aksraj 21 Mar, 2009
Hi,

Here's my scenario.I need to create a single button which when clicked will enter the currently logged in users name into the database.Can someone help me with this?
GreyHead 21 Mar, 2009
Hi aksraj,

Create a form with just a submit button and use the DB Connection to save the user id.

Bob
aksraj 22 Mar, 2009
I created a single button.What do i do at the db connection page?
GreyHead 22 Mar, 2009
Hi aksraj,

Make a connection to the table where you want to save the data; or if you want a new table use the 'Create Table' icon in the forms manager to to this.

You'll need one hidden field in your form to contain the user id.

Bob
aksraj 22 Mar, 2009
<?php
   $user = JFactory::getuser();
?>

<div
<input type="hidden" name="username" value="<?php echo $user; ?>" />
</div>

<div class="form_item">
  <div class="form_element cf_button">
    <input value="Register for talk" type="submit" />
  </div>
  <div class="clear"> </div>
</div>


This is the code i used in the form html.I've done all the table creation and db connection.It doesnt seem to work though.When i click the button the table reads
username : Object
GreyHead 22 Mar, 2009
Hi askraj,

A few small changes
<?php
   $user =& JFactory::getUser();
?>

<div
<input type="hidden" name="username" value="<?php echo $user->id; ?>" />
. . .

Bob
aksraj 22 Mar, 2009
That gives me the id,cant i get the username?
GreyHead 22 Mar, 2009
Hi aksraj,

$user->name or $user->username

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