Can I customize form based on registered user login?

swilliford 01 Nov, 2008
I want to build a form that allows users to log in, go to the form and see a dynamic form based on their user profile. Each user will provide family members names (child1, child2, child3, etc.) when registering for the site and will be stored in their profile. then after they log in, their form will have check boxes beside their children's names to register them for an event. I plan on using CB to manage the users and want to use ChronoForms to build the form and create a db of the submitted data. Is that possible?

Scott
GreyHead 01 Nov, 2008
Hi swilliford,

Yes that's possible.

You can use the CB Registration plugin that comes in the CF Forms Manager to manage the registrations. Then you'll need some custom work to manage the children. Will the main registration be per family - or per parent i.e. could Mom & Dad register seperately? I'd be inclined to buidl a separate children data table and use the parent/family ID code to link them together.

Bob
swilliford 01 Nov, 2008
Thanks for the reply. I found the following to help me set up the CB Plugin

http://www.navigatetomorrow.com/pdfs/Chronoforms_how_to_build_registration_page.pdf

I assume it is very similar but how do I set up multiple tables using this integration. FYI.. I am not a developer but understand DB tables, interlinks, etc.

The site is for a swim team and right now we allow swimmers and their parents to register. My thought is to set Parents up as a separate user group so they can register their swimmers for events. I love the idea of a separate table of the swimmers (children) and linking it to families (mom's account and dad's account). But if I had to I would set one parent per family to register the swimmers. That way I wouldn't have to worry about validating to see if mom already registered the kids if dad was attempting to.

is there a tutorial to helps me set up the multiple table registration process and another one that helps me get the form to pull from the those tables to create the registration forms.

Thanks again for your help.
GreyHead 01 Nov, 2008
Hi swilliford,

Yes that's the tutorial to set up the Registration. Either by extending that form, or on a new form you're going to need some way for them to add children. You can do that in a simple ChronoForms form saving to a database table. Make the form only availalbe to logged in users so that you can save the parent id with the child info.

Then you'll need a third form for event regiatration. Again make it available only to logged in members and in the form HTML you'll need to add a little bit of code to look up the children table and show their children with checkboxes to enter them. There's a second CF plugin that will help with this I think.

Sounds complicated but taken step by step isn't too bad at all.

Bob
swilliford 01 Nov, 2008
Great... I think I understand. Two questions:

1. How do I link the log in to the form so I can connect the parent id to the second form for the swimmers names?
2. Do you know where I can find the "There's a second CF plugin that will help with this I think." that allows me to dynamically create the third form?

I really appreciate your help on this.
swilliford 01 Nov, 2008
I got some of it figured out. I am now using

<input type="hidden" name="user_id" value="<?php $my = JFactory::getuser(); echo $my->id; ?>" />

To get the user ID... so I can figure out how to do create the second form and link the swimmers to the parents user id.

Now I need to know how to search that table to pull up the swimmers for the registration form?
swilliford 01 Nov, 2008
I just realized something. I need a separate row for every registration. So if a family has 3 kids that all want to go to the event I need to have three rows in the database. I am thinking I will use the children/swimmer table to populate a drop down then let them select one, once they submit I will give them a chance to go back to the form to submit another.

1. What is the easiest way to pull data from a table to put into the drop down?
2. Can I also use this to pull other data like the child's birthday?
3. Lastly, how do I make sure that this specific child has not already registered for the event?

My ultimate goal is to have it so every time a new event is put on our calendar I can go into ChronoForms, duplicate the form with a new name and have a new registration form link to put on the calendar.

I really appreciate your help so far and think I am on my way.

Scott
Max_admin 01 Nov, 2008
Hi Scott,

the answer to your last 3 questions is pure PHP and SQL, you need SQL to load the data from tables then PHP to put it or process it the way you like, searching the forums for the word "SELECT" will bring many statements like this and how they should work! look at some of them to see how its done and ask if you have problems!

Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
swilliford 02 Nov, 2008
Thanks MAX,

I found 466 results when I searched "SELECT" unfortunately after looking at 16 pages of the results I still saw nothing I could understand that matched my needs. This might just be over my head. I'll keep looking but if you could narrow my search a little I would appreciate it.

Thanks again.

Scott
GreyHead 02 Nov, 2008
Hi Scott,

Part of the problem is that you are building an application here and the forms are just a small - but critical - part of it. I can see a small group of data tables here: [list]
  • users (for parent registrations)
  • children (one record per child)
  • parents-children (a table to link parents to children where records just have the two ids)
  • Events (one record per event with the info about the event)
  • Entrants (one record per entrant that links the child to the event)
  • [/list]Alongside this go several forms[list]
  • Registration (adds parents to the database)
  • Child registration (add children to the database - and optionally, identify the other parent if they are registered - updates the parents-children & children tables)
  • Events (administrator entry form)
  • Event entry (shows currently open events, lists viewers children and allows them to be added to events)
  • Most likely some public event listings - maybe display only
  • [/list]Most of these forms are going to need to be capable of editing entries as well as adding them.

    Max is right, PHP & SQL are the mechanism that ties all this together. You can do this one step at a time but keeping the overall plan in mind. I'd start out with the Registration and Child entry forms, then the Events and lastly add the Entrant form as this needs the other data in place.

    Bob
    Max_admin 02 Nov, 2008
    here is an example of a select statement, its not the default one, you must change it based on the code structure you will use, like what Bob suggested.

    $database->setQuery( "SELECT * FROM #__tablename WHERE fieldname='".$fieldvalue."'" );
    	$fielddata = $database->loadObject();


    Max
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    swilliford 02 Nov, 2008
    Thank you both for your help. I have built the tables the way I want them. Fortunately, I had a good idea of how to do that on the start of the project. It looks like I am going to have to learn more PHP and SQL than I wanted to do what I need. If not I'll get a friend to help me with the PHP and SQL statements to complete the project. Once done I'll post it back up so others can see how it was completed. Thanks again for your feedback.

    Scott
    swilliford 05 Nov, 2008
    Hey guys, I feel like I am making some headway but I've run into something I can't quite figure out. In building the tables I decided it would be worth while having a list of swimmers associated with the current user. That way when they go to add swimmers they'll see who they have already added. So what've I've got working is the following. But I have had to hard code the WHERE user_id='64' to get a result.

    <?php
    $database = &JFactory::getDBO(); // only needed once
    $query = "SELECT * FROM jos_chronoforms_swimmers 
    WHERE user_id='64'";
    $database->setQuery( $query );
    $rows = $database->loadObjectList();
    //$count = $database->getNumRows();
    //echo "count: $count<br />";
    echo "<table>";
    foreach ($rows as $row) {
        echo "<tr>";
            foreach ($row as $value) {
                echo '<td>' .$value .'</td>';
            }
        echo "</tr>";
    }
    echo "</table>";?>


    How do I make it specific to the user logged in?
    Max_admin 05 Nov, 2008
    your code edited:

        <?php
        $database = &JFactory::getDBO(); // only needed once
    $user = JFactory::getuser();
        $query = "SELECT * FROM jos_chronoforms_swimmers
        WHERE user_id='".$user->id."' ";
        $database->setQuery( $query );
        $rows = $database->loadObjectList();
        //$count = $database->getNumRows();
        //echo "count: $count<br />";
        echo "<table>";
        foreach ($rows as $row) {
            echo "<tr>";
                foreach ($row as $value) {
                    echo '<td>' .$value .'</td>';
                }
            echo "</tr>";
        }
        echo "</table>";?>
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    swilliford 06 Nov, 2008
    Thanks... that's what I needed. On with my PHP education. My next step is to limit the fields that display. Also, I assume the same type logic will be used when I get to my next form that lets these swimmers register for events. Thanks again.
    GreyHead 06 Nov, 2008
    Hi swilliford,

    Replace 'SELECT * . . .' with 'SELECT column_name1, column_name2, . . .' for the database columns that you want to display.

    Bob
    swilliford 06 Nov, 2008
    Thanks Bob, I figured that out last night and actually got the dynamic drop down working the way I needed on the event registration form. It shouldn't take me too long to complete everything at this point. It's actually working now but I want to make it pretty. This has turned into a great experience and I've learn how easy it is with just a few PHP/mySQL statements how easy it is to build an application with Chronoforms. Thank you and Max both for your guidance and support.

    Scott
    GreyHead 06 Nov, 2008
    Hi Scott,

    Congratulations - well done :-)

    Bob
    swilliford 07 Nov, 2008
    I spoke a bit too soon. I don't know how to pull additional data from the swimmers table into the registration table when the user selects the swimmer they are registering. For example, I offered them the first name in the drop down but want to pull the last name and birthday into the registration table on the same record. Even if I decided to interjoin the two tables later I would still need the key field to pulled for the right swimmer after the user selected a name. Here is part of my form. What do I add to pull the other fields I need after the dropdown selection is made by the user?

       <?php
        $database = &JFactory::getDBO(); // only needed once
        $user = JFactory::getuser();
        $query = "SELECT first_name FROM jos_chronoforms_swimmers
        WHERE user_id='".$user->id."' ";
        $database->setQuery( $query );
        $rows = $database->loadObjectList();
        foreach ($rows as $row) {
      $selectOptions .= "<option value=\"$row->first_name\">$row->first_name</option>";
    }
    ?>
    <div  class="form_item"><div class="form_element cf_dropdown"><label class="cf_label">Click Me to Edit</label>
    <select class="cf_inputbox" id="select_0" size="1" name="select_0"><option value="">Any</option>
      <?php echo $selectOptions ?>
    </select></div>


    I am real close and feel really good about it. Thanks again for your help.

    Scott
    Max_admin 07 Nov, 2008
    Hi Scott,

    why not include another SELECT in the foreach ?

    Cheers
    Max
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    swilliford 07 Nov, 2008
    Max,

    I am not sure how to do that. my goal is to keep first_name, last_name and birthday in separate fields when the form posts. so when the user picks swimmer1's first_name, the form will automatically grab last_name and birthday. I don't want to add more dropdowns but wanted the last_name and birthday to be hidden inputs looked up as a result of the first_name selection.

    Scott
    Max_admin 07 Nov, 2008
    I got it now, so when somebody chooses any dropdown option, 2 hidden fields will get loaded with the last name and BD of this firstname choosed ? you will need JS or maybe AJAX to achieve this!

    Max
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    swilliford 08 Nov, 2008
    Max,

    I agree now that I have read what AJAX does and found some great examples of AJAX through Google. Is there a tutorial on how to implement AJAX in Chronoforms or can you give me a simple example form I can look at? Also, I may need to allow folks to edit their event registrations, a little example of a form that allows editing would be great as well.

    Scott
    Max_admin 08 Nov, 2008
    Hi Scott,

    To edit records you will need to get the coming soon version of ChronoConnectivity or wait for a new version of the profiler plugin for Chronoforms!

    for the AJAX part, do you have any PHP experience ? AJAX means JS + PHP, doing the task above will need some work to do, I can help but if you have no experience with PHP then it may be hard to follow me.

    Let me know!

    Regards,
    Max
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    swilliford 10 Nov, 2008
    I am learning PHP and have done enough research to know how AJAX works. I have found some examples and think I follow them. I fully understand if you think this is over my head but I enjoy learning it and have been able to create the first dynamic drop down with just a little help.

    Scott
    Max_admin 10 Nov, 2008
    Ok good, lets do it, first step is to create another form, give it a name "ajaxform1" and in the form HTML, add PHP to generate the 2 hidden fields with the last name and birthday, show me the code you do after you finish it.

    Regards
    Max
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    swilliford 10 Nov, 2008
    I am not exactly sure I am doing this right but here we go.

    <?php
        $database = &JFactory::getDBO();
        $swimmer_id = [NOT SURE HOW TO GET THIS];
        $query = "SELECT last_name,birthday FROM jos_chronoforms_swimmers
        WHERE swimmer_id='".$swimmer->id."' ";
        $database->setQuery( $query );
        $last_name = $database->last_name;
        $birthday = $database->birthday;
        ?>
    <div
    <input type="hidden" name="last_name" value="<?php echo $last_name; ?>" />
    <input type="hidden" name="birthday" value="<?php echo $birthday; ?>" />
    </div>
    Max_admin 10 Nov, 2008
    Here is a fixed version of your code:

    
        <?php
            $database = &JFactory::getDBO();
            $swimmer_id = JRequest::getVar('swimmer_id');
            $query = "SELECT last_name,birthday FROM jos_chronoforms_swimmers
            WHERE swimmer_id='".$swimmer->id."' ";
            $database->setQuery( $query );
    $data = $database->loadObject();
            $last_name = $data->last_name;
            $birthday = $data->birthday;
            ?>
        <div
        <input type="hidden" name="last_name" value="<?php echo $last_name; ?>" />
        <input type="hidden" name="birthday" value="<?php echo $birthday; ?>" />
        </div>
    
    


    more code to follow!
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    Max_admin 10 Nov, 2008
    I will assume your form has a dropdown like this:
    
    <select name="swimmers" id="swimmers" onChange="load_other_data()">
    <option value="1">geaorge</option>
    <option value="2">Lois</option>
    </select>
    <div id="my_hidden_fields_container"></div>
    


    now, at the JS box:

    function load_other_data()() {
    	var url = "index2.php?option=com_chronocontact&chronoformname=ajaxform1&swimmer_id=" + $('swimmers').value;
    	new Ajax(url, {
    		method: 'get',
    		update: $('my_hidden_fields_container'),
    		onComplete: function(){ 
    			alert('woohaa, its working!!'); // can be commented
    			}
    		}
    	}).request();	
    }


    let me know!

    Regards
    Max
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    swilliford 11 Nov, 2008
    My initial form has the following code

     <?php
        $database = &JFactory::getDBO(); // only needed once
        $user = JFactory::getuser();
        $query = "SELECT first_name FROM jos_chronoforms_swimmers
        WHERE user_id='".$user->id."' ";
        $database->setQuery( $query );
        $rows = $database->loadObjectList();
        foreach ($rows as $row) {
        $selectOptions .= "<option value=\"$row->first_name\">$row->first_name</option>";
    }
    ?>
    <div  class="form_item"><div class="form_element cf_dropdown">
    	<label class="cf_label">Select Swimmer</label>
    	<select class="cf_inputbox" id="select_0" size="1" name="select_0">
    	<option value="">Any</option>  <?php echo $selectOptions ?></select>
    </div>
    <div class="clear"> </div>
    <div class="form_item"><div class="form_element cf_checkbox">
    	<label class="cf_label">Days Attending</label>
    	<div class="float_left">
    	<input value="Friday" class="radio" id="Friday" name="Friday" type="checkbox">
    		<label for="Friday" class="check_label">Friday</label><br>
    	<input value="Saturday" class="radio" id="Saturday" name="Saturday" type="checkbox">
    		<label for="Saturday" class="check_label">Saturday</label><br>
    	<input value="Sunday" class="radio" id="Sunday" name="Sunday" type="checkbox">
    		<label for="Sunday" class="check_label">Sunday</label><br></div></div>
    <div class="clear"> </div></div>
    <div class="clear"> </div></div>
    <div  class="form_item"><div class="form_element cf_button">
    	<input value="Submit" name="undefined" type="submit"></div>
    <div class="clear"> </div></div>
    


    I assume I will have to use the selected swimmer's first_name and the current user's user_id to figure out the last_names, etc. Let me give that a shot and I'll let you know how it goes. I am learning so much. thanks for your help.
    swilliford 11 Nov, 2008
    MAX,

    I am struggling just a little. below are is the code I have built but it doesn't seem to pull the additional hidden fields.

    DYNAMIC DROP DOWN FORM

    <?php
       $database = &JFactory::getDBO();
       $first_name = JRequest::getVar('first_name');
       $user = JFactory::getuser();
       $query = "SELECT last_name,birthday FROM jos_chronoforms_swimmers
            WHERE first_name='".$first_name->id."' AND user_id='".$user->id."' ";
       $database->setQuery( $query );
       $data = $database->loadObject();
       $last_name = $data->last_name;
       $birthday = $data->birthday;
    ?>
    <div
    <input type="hidden" name="last_name" value="<?php echo $last_name; ?>" />
    <input type="hidden" name="birthday" value="<?php echo $birthday; ?>" />
    </div>


    JAVA script

    function load_other_data()() {
       var url = "index2.php?option=com_chronocontact&chronoformname=ajaxform1&first_name=" + $('first_name').value;
       new Ajax(url, {
          method: 'get',
          update: $('my_hidden_fields_container'),
          onComplete: function(){
             alert('woohaa, its working!!'); // can be commented
             }
          }
       }).request();   
    }


    ajaxform1

    <?php
       $database = &JFactory::getDBO();
       $first_name = JRequest::getVar('first_name');
       $user = JFactory::getuser();
       $query = "SELECT last_name,birthday FROM jos_chronoforms_swimmers
            WHERE first_name='".$first_name->id."' AND user_id='".$user->id."' ";
       $database->setQuery( $query );
       $data = $database->loadObject();
       $last_name = $data->last_name;
       $birthday = $data->birthday;
    ?>
    <div
    <input type="hidden" name="last_name" value="<?php echo $last_name; ?>" />
    <input type="hidden" name="birthday" value="<?php echo $birthday; ?>" />
    </div>


    Notice I added the AND user_id='".$user->id."' so I could get the right last names and birth days. It seems to work on the front end but I am not getting any of the hidden fields in the database.

    Scott
    Max_admin 11 Nov, 2008
    Hi Scott,

    Whats "$first_name->id" ? it should be "$first_name" only I guess ?

    how do you know its working in the frontend ? do you check the page source or inspect the HTML with firefox firebug ?

    Max
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    This topic is locked and no more replies can be posted.