Forums

uid variable & accessing row for update

awilkin 22 Aug, 2010
Hi Forum,

On the redirect I am passing the uid variable in the query string, how do I get this and put into a hidden variable within the form on the redirected page?

Indeed if anyone can also tell me how to load up the record for updating using that uid that would be cool. I don't want to pass the cf_id across as that is not very secure.

Thoughts?

Andy
GreyHead 22 Aug, 2010
Hi Andy,

Use this code (or something like it) in the Form HTML
<?php
if ( !$mainframe->isSite() ) { return; }
$uid =& JRequest;getString('uid', '', 'get');
?>
. . .
<input type='hidden' name='uid' value='<?php echo $uid; ?>' />


The Profile Plugin is the easiest way to reload the data, or you can add the MySQL query to look the data up and echo into the values.

Bob
awilkin 22 Aug, 2010
Bob,

Thanks for the quick response. Couple of questions here:

1. Can you point me to the documentation of the profile plugin (you see still waiting to buy your book)

2. I have worked out how to pull the cf_id from the database, but next question is how I prevent people from accessing the page if the cf_id value pulled back from the database is null? Ideally I would like to redirect them to my 404 page.

Thanks,

Andy
GreyHead 22 Aug, 2010
Hi Andy,

Here are the contents of the Help tab - should be enough to get you going:

Help for Profile Table plugin
The plugin allows you to read values from any table in the database and include them in your form.
It was originally designed to allow access to the jos_users table to create member profiles but it is capable of much more.
To use the plugin effectively you will need to call the form from a link on your site. This could be from - for example a list of users, or topics, or events where you have some related information in a database table.

* Choose the table you want to use in the first drop-down e.g. jos_users to get a user's name and email.
* Select a field or column name from the table in the second drop down. This should be a field that will uniquely identify the record you want to use e.g. 'id' or 'username' for the jos_user table. NB This drop-down will not appear until you select a table in the first drop-down.
* In the Target field name box put the name of the field you will use to identify the record e.g. user_id. You will need to add this field to a url calling the form e.g. . . . &chronoformname=my_form&user_id=99
* You can then use information from this record in your form by putting {column_name} where you want it to appear e.g. {name} for a users name from the jos_users table.
* Once this plugin is configured you must enable it in the Form 'Plugins' tab.



To redirect use this code:
<?php
if ( !$mainframe->isSite() ) { return; }
$uid =& JRequest;getString('uid', '', 'get');
if ( !$uid ) {
  $mainframe->redirect('404');
}
?>




Bob
awilkin 22 Aug, 2010
Bob,

Will give the profile thing ago. But always have more questions...

1. The redirect works so well it redirects the admin screen as I click save rather than saving it to the database - thoughts?

2. I have set the cf_id in the form (I can see it in the source of the page), but does not update the record in the database. Have I missed a step?

Thanks again,

Andy
awilkin 22 Aug, 2010
Ignore the part about the database update, I tried again from the start and it updates now. Just need to sort out the redirect...

Thanks,

Andy
GreyHead 22 Aug, 2010
Hi Andy,

The first line *should* prevent that - have you got the ! correct in
<?php
if ( !$mainframe->isSite() ) { return; }
. . .
?>


Bob
awilkin 22 Aug, 2010
Bob,

You rock🙂

I had not understood the significance of the return statement - I do now...

With your help I have achieved so much this weekend, including a complex multiform approach that allows me flexibility in my landing pages yet still records the data.

Cheers,

Andy
the_fitz 04 Oct, 2010
I have read every post about the profile pages, and even though I get the concept I can't get it to work.

Following the instructions below:
Choose table OK
Choose field, OK, I picked CF_ID (in lower case)
Target field, I'm LOST. I figured it would also be the same so I tried CF_ID (in lower case)
URL, I'm LOST. Where do you put it? There is no spot on the plugin to put it, so where does it go, and how the heck do I add the CF_ID to it? The form links shows:
index.php?option=com_chronocontact&chronoformname=profile
but it is not editable and how would I add a variable to equal a variable like cf_id = cf_id???? That makes no sense to me. if I mimic the example below:
e.g. . . . &chronoformname=my_form&cf_id=99
I will always get the record #99 !!!!
{column name}, I'm lost again. Where does that go? I have already built the form, and already connected the database table. I see no place in the plugin to add it. I can't see how it would be added to the "Form Code" section of the form code??? There is no place to put it without replacing the field name or id. I figured that maybe it would go into the "Value" field of each text field (click here to edit), but several posts say that is wrong???? What is correct??

So, I am stupid. I can only figure out how to use 2 of the 5 instructions in the help menu. Boy, I even feel stupid!!!

Please help, I'm just stupid now, but by morning, I may be a moron!!!
the_fitz




Hi Andy,

Here are the contents of the Help tab - should be enough to get you going:

Help for Profile Table plugin
The plugin allows you to read values from any table in the database and include them in your form.
It was originally designed to allow access to the jos_users table to create member profiles but it is capable of much more.
To use the plugin effectively you will need to call the form from a link on your site. This could be from - for example a list of users, or topics, or events where you have some related information in a database table.

* Choose the table you want to use in the first drop-down e.g. jos_users to get a user's name and email.
* Select a field or column name from the table in the second drop down. This should be a field that will uniquely identify the record you want to use e.g. 'id' or 'username' for the jos_user table. NB This drop-down will not appear until you select a table in the first drop-down.
* In the Target field name box put the name of the field you will use to identify the record e.g. user_id. You will need to add this field to a url calling the form e.g. . . . &chronoformname=my_form&user_id=99
* You can then use information from this record in your form by putting {column_name} where you want it to appear e.g. {name} for a users name from the jos_users table.
* Once this plugin is configured you must enable it in the Form 'Plugins' tab.



To redirect use this code:
<?php
if ( !$mainframe->isSite() ) { return; }
$uid =& JRequest;getString('uid', '', 'get');
if ( !$uid ) {
  $mainframe->redirect('404');
}
?>




Bob

GreyHead 05 Oct, 2010
Hi the_fitz,

What are you actually trying to do here?

The profile plug-in is designed to be called from a URL somewhere on your website and to select a single record based on the information in the URL. You can get it to work other ways depending on what you need.

There's a typo (my fault) I the help: in the third bullet "Target field name" should be "Request parameter name". This will usually be the same as the Target field but doesn't have to be. The Target filed is a column in the database; the Request parameter is a part of the URL query string.

The {column_name} entries go into the Form HTML box - they will be used to display the information retrieved from the Database record (or, if 'Editable' is set to Yes, to edit the record).

Bob
the_fitz 05 Oct, 2010
Ignore the below stuff. I got it to work. I redid the form and resetup the plugin and it started working... I don't know why it wasn't working before???

Thanks again for your attention
The_fitz


-----------------------------------------------------------------------------
Thanks, believe it or not, I get it all, except... how to develop the Request Parameter.
I know I need to add it into the field on the screen but where do I get the info from?

DETAILS
This is a registration profile view and edit situation where I want the user, once logged in to joomla to me redirected to the profile (this) page to make sure that their info is up to date, and edit it if need be. I believe I have to get a parameter from the users login to be able to display that exact record. If I was using pure php i would do a db select statement using the logged in user Id like.

select * from cf_users where cf_id = SESSION['cf_id']

to find the record

OR I would pass a parameter from a previous program with a GET and then the query would be something like

select * from cf_users where cf_id = $_GET['cf_id']

to find the record.

This is where I am lost here....

What do I put into the Request Parameter? ( I would think this would pass a parameter FROM this program to another, but that is a whole other issue. )

My table name is jml_chronoforms_registration. My unique index field is cf_id. I also have the cf_user_id which is unique and equal to jml_user.id

I am going to be linking several different profile pages to this account so if you could show me the code for both solutions,
1. getting the logged in "id" from the joomla environment
2 getting the GET data from a passed previous program
so I can correctly display the profile pages, I would greatly appreciate it.

Thanks in advance for your superior support.

the_fitz
GreyHead 05 Oct, 2010
Hi the_fitz,

Great, I was just about to write a reply :-)

Bob
the_fitz 05 Oct, 2010
Thanks again, Bob. Please explain how I would put this at the end of a URL. &cf_id=76 like:
http://mydomain.com/index.php?option=com_chronocontact&Itemid=14&cf_id=76

You mention it in the Profile Plugin help. But I have not been able to find a way to do it. It would have to be a variable, of course, like &cf_id=<?php echo $cf_id ; ?> but where would I put it in Joomla to have it pass this parameter to a called form?

Thanks, again, in davance for the great service!
the_fitz
GreyHead 06 Oct, 2010
Hi the_fitz,

There's no general answer to this - it depends on what you are trying to do.

One classic example would be to show details from a Chronoconnectivity listing. In that case I'd generate a URL & link for each entry on the listing like
<a href='index.php?option=con_chronocontact&chronoformname=xxx&cf_id={cf_id}'>View details</a>
Then ChronoConnectivity would replace {cf_id} with the id of that particular record.

Bob
the_fitz 06 Oct, 2010
Ok, I get it. but I think that means that I am confused about something else...

does that mean that I Can't use chronoforms to generate a table, instead I have to use ChronoConnectivity?

I was thinking :

<?php
query....
?>
<table width="100%" border="1" cellpadding="1" cellspacing="1" id="usagehist">
   <tr>
      <th width="25%" scope="col">Transaction Date </th>
      <th width="26%" scope="col">Location</th>
      <th width="19%" scope="col">Amount Transacted </th>
      <th width="16%" scope="col">Type</th>
   </tr>
<?php 
while...
get row from query
?>  
 <tr>
      <td>{tran_date}</td>
      <td>{tran_store}</td>
      <td>{tran_dollars} </td>
      <td>{tran_type}</td>
   </tr>
<?php
end while..
?>
</table>




I was going to do this in a Chronoform, am I wrong??? Now I'm thinking my concept is wrong.
Please clarify this for me.
Thanks, in advance. Your support is great!
the_fitz

Hi the_fitz,

There's no general answer to this - it depends on what you are trying to do.

One classic example would be to show details from a Chronoconnectivity listing. In that case I'd generate a URL & link for each entry on the listing like

<a href='index.php?option=con_chronocontact&chronoformname=xxx&cf_id={cf_id}'>View details</a>
Then ChronoConnectivity would replace {cf_id} with the id of that particular record.

Bob

GreyHead 06 Oct, 2010
Hi the_fitz,

does that mean that I Can't use chronoforms to generate a table, instead I have to use ChronoConnectivity?

Ther's no "can't" or "have to" here; it's just a question of what does the job best.

You can create a perfectly good table -- as you have -- in ChronoForms (and build links in a similar way); or you can use ChronoConnectivity which is designed to create lists of records from tables and which may make the task a little simpler.

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