Can I do this with ChronoForms?

vincentp 02 Apr, 2009
Hi,
I need a registered user to be able to upload one or more mp3 files and an acompanying piece of text. Later only that specific user should be able to see and edit the file and the text on a sort of private homepage.
Can anyone tell me if this is doable using chronoforms? Or should I make a component from scratch?

Kind regards,

Vincent
GreyHead 02 Apr, 2009
Hi Vincent,

You can do this with a single ChronoForms form. At the beginning of the Form HTML you'll need some code to get the user id, check if they have an existing record then either show them the upload form or their 'private' homepage.

Bob
vincentp 02 Apr, 2009
Hi Bob,

Thanks for your quick reply!
I am not a Joomla expert, I know I can get the user ID with
$user =& JFactory::getUser();
$user->get('id');

But I would not have a clue as to how I would check if a record already exists... Can you suggest a method?

Cheers,

Vincent
GreyHead 02 Apr, 2009
Hi Vincent,

Not exact without knowing how your form and table are set up but it will be something like:
<?php
$user =& JFactory::getUser();
$db =& JFactory::getDBO();
$query = "
  SELECT count(*) 
    FROM `#__some_table` 
    WHERE `id` = $db->Quote($user->id) ";
$db->setQuery($query);
$count = $db->loadResult();
If ( $count) {
  // user has a record
} else {
  // user doesn't have a record
}
?>
vincentp 02 Apr, 2009
Great🙂

I have not set up anything yet as I am exploring the possibilities, but it seems ChronoForms will be what I need.

I am thinking of a DB table with the fields userID,File,Image,Text,Otheruser_1, OtherUser_1Pass,Otheruser_2, OtherUser_2Pass, where userID needs to be linked with the Joomla User table, File and Image would contain URL's to the corresponding file and image, and Text would be a simple MySQL text field. the four Otheruser fields would contain a username and password for someone other than the registered user, they would need to be able to view the registered users page too when using the proper username and password on the user page.

Long story... did I manage to clarify?
Thanks again for your help!

Vincent
GreyHead 02 Apr, 2009
Hi Vincent,

That will work OK. A fairly straightforward form. How are you going to identify the 'Other Users'? are they Registered site users? If so I'd feel inclined to store their Userids (or usernames) only here and use the Joomla code to check that they are logged in and the ids match.

Bob
vincentp 02 Apr, 2009
Hi Bob,

No the Otherusers are not registered members, they would need to view the page through a different login form. I was thinking along these lines:

The Registered user would get this page:
<?php
$user =& JFactory::getUser();
$db =& JFactory::getDBO();
$query = "
  SELECT count(*) 
    FROM `#__some_table` 
    WHERE `id` = $db->Quote($user->id) ";
$db->setQuery($query);
$count = $db->loadResult();
If ( $count) {
  // user has a record
  // Display file, text and image
  // Display Edit link !!!!!!!!!  How? Link to the same form again?	

} else {
  // user doesn't have a record
  // Display Input Form
}
?>



The Otherusers would use a special ChronoForm login page with a username and password field:
<?php

$db =& JFactory::getDBO();
$query = "
  SELECT count(*) 
    FROM `#__some_table` 
    WHERE `OtherUser_1` = $db->ChronoForm username AND `OtherUser_1Pass` = ChronoForm password";
$db->setQuery($query);
$count = $db->loadResult();
If ( $count) {
  // OtherUser entered the right info
  // Display file, image and text	

} else {
  // OtherUser entered the wrong info
  // Display Input Error
}
?>


I do not know at this point how I would check if by any chance it was OtherUser_2 who entered the form though.

regards Vincent
GreyHead 02 Apr, 2009
Hi Vincent,

To link to the same form again make sure that the key data is in hidden fields so that you can re-identify the record to display and simply link to the form URL adding '&task=edit' or something similar to the url. Then check the GET variables in your Form HTML and if task = edit display the form for editing.

For the passwords, I'm inclined to make it a bit simpler by adding another table with user_id, viewer_id, viewer_name, viewer_password. Then you don't have to store the viewer names and passwords in the user file. Then you look for a match with the user_id, and viewer info in the new table. That way it doesn't matter which viewer (and you could have more than two using the same code).

Bob
vincentp 02 Apr, 2009
That is indeed a very elegant solution, I'll do that. I'm well on the way with Chronoforms by now, its an excellent piece of software! Thanks for your great help, I will update this with the result!

Regards,
Vincent
This topic is locked and no more replies can be posted.