Forums

Form Problem? (Can this be done? How is it done?)

dyerdyerdyer 15 Mar, 2009
Hi

I hope somebody can help.

I would like a form which allows one specific user to select an event, each event may have 30 users registered, but the form must only allow 14 users to be selected for the event. It's for a football team where i simply want to select 11 players and 3 subs. So the form needs to recognize that depending on what event is selected will determine what users have registered. I would like the selecting of each particular event and user to be done through a drop down list. At the end of the form I would like a submit button that sends an email to every user in the whole system detailing the selection and also recording the information in a database table.

I believe I have the database set up ready. Im using EventList, CB and of course CHRONO FORMS

What I need is a little guidance on how I might fix this problem, the code I have at the moment is below, I can select events and users although the only users I can select are the ones that have registered to the first event that is displayed from the event drop down list. I.e if i select a different event, the users that are register are then not displayed.

<p>Team Selection</p>
<label>Choose Fixture  </label>
<select name="somefield">
<?php
$db = JFactory::getDBO();
$db->setQuery("SELECT id, title FROM jos_eventlist_events WHERE dates > CURDATE()");
$events = $db->loadObjectList();
foreach ($events as $event) {
  echo ('<option value="' . $event->id . '">' . $event->title . '</option>');
}
?>

</select>

<p><br />Starting Eleven</p>
<label><br />1.  </label>
<select name="one">
<?php
$db = JFactory::getDBO();
$db->setQuery("SELECT name FROM jos_users INNER JOIN jos_eventlist_register ON jos_users.id = jos_eventlist_register.uid");
$availables = $db->loadObjectList();
foreach ($availables as $available) {
  echo ('<option value="' . $available->id . '">' . $available->name . '</option>');
}
?>


</select>

<label>	</br><br /><br />2.  </label>
<select name="two">
<?php
$db = JFactory::getDBO();
$db->setQuery("SELECT name FROM jos_users INNER JOIN jos_eventlist_register ON jos_users.id = jos_eventlist_register.uid");
$availables = $db->loadObjectList();
foreach ($availables as $available) {
  echo ('<option value="' . $available->id . '">' . $available->name . '</option>');
}
?>

</select>

<label>	</br><br /><br />3.  </label>
<select name="three">
<?php
$db = JFactory::getDBO();
$db->setQuery("SELECT name FROM jos_users INNER JOIN jos_eventlist_register ON jos_users.id = jos_eventlist_register.uid");
$availables = $db->loadObjectList();
foreach ($availables as $available) {
  echo ('<option value="' . $available->id . '">' . $available->name . '</option>');
}
?>

</select>

<label>	</br><br /><br />4.  </label>
<select name="four">
<?php
$db = JFactory::getDBO();
$db->setQuery("SELECT name FROM jos_users INNER JOIN jos_eventlist_register ON jos_users.id = jos_eventlist_register.uid");
$availables = $db->loadObjectList();
foreach ($availables as $available) {
  echo ('<option value="' . $available->id . '">' . $available->name . '</option>');
}
?>

</select>

<label>	</br><br /><br />5.  </label>
<select name="five">
<?php
$db = JFactory::getDBO();
$db->setQuery("SELECT name FROM jos_users INNER JOIN jos_eventlist_register ON jos_users.id = jos_eventlist_register.uid");
$availables = $db->loadObjectList();
foreach ($availables as $available) {
  echo ('<option value="' . $available->id . '">' . $available->name . '</option>');
}
?>

</select>

<label>	</br><br /><br />6.  </label>
<select name="six">
<?php
$db = JFactory::getDBO();
$db->setQuery("SELECT name FROM jos_users INNER JOIN jos_eventlist_register ON jos_users.id = jos_eventlist_register.uid");
$availables = $db->loadObjectList();
foreach ($availables as $available) {
  echo ('<option value="' . $available->id . '">' . $available->name . '</option>');
}
?>

</select>

<label>	</br><br /><br />7.  </label>
<select name="seven">
<?php
$db = JFactory::getDBO();
$db->setQuery("SELECT name FROM jos_users INNER JOIN jos_eventlist_register ON jos_users.id = jos_eventlist_register.uid");
$availables = $db->loadObjectList();
foreach ($availables as $available) {
  echo ('<option value="' . $available->id . '">' . $available->name . '</option>');
}
?>

</select>

<label>	</br><br /><br />8.  </label>
<select name="eight">
<?php
$db = JFactory::getDBO();
$db->setQuery("SELECT name FROM jos_users INNER JOIN jos_eventlist_register ON jos_users.id = jos_eventlist_register.uid");
$availables = $db->loadObjectList();
foreach ($availables as $available) {
  echo ('<option value="' . $available->id . '">' . $available->name . '</option>');
}
?>

</select>

<label>	</br><br /><br />9.  </label>
<select name="nine">
<?php
$db = JFactory::getDBO();
$db->setQuery("SELECT name FROM jos_users INNER JOIN jos_eventlist_register ON jos_users.id = jos_eventlist_register.uid");
$availables = $db->loadObjectList();
foreach ($availables as $available) {
  echo ('<option value="' . $available->id . '">' . $available->name . '</option>');
}
?>

</select>

<label>	</br><br /><br />10.  </label>
<select name="ten">
<?php
$db = JFactory::getDBO();
$db->setQuery("SELECT name FROM jos_users INNER JOIN jos_eventlist_register ON jos_users.id = jos_eventlist_register.uid");
$availables = $db->loadObjectList();
foreach ($availables as $available) {
  echo ('<option value="' . $available->id . '">' . $available->name . '</option>');
}
?>

</select>

<label>	</br><br /><br />11.  </label>
<select name="eleven">
<?php
$db = JFactory::getDBO();
$db->setQuery("SELECT name FROM jos_users INNER JOIN jos_eventlist_register ON jos_users.id = jos_eventlist_register.uid");
$availables = $db->loadObjectList();
foreach ($availables as $available) {
  echo ('<option value="' . $available->id . '">' . $available->name . '</option>');
}
?>

</select>

<p><br />Substitutes</p>


<label>	</br><br /><br />12.  </label>
<select name="nine">
<?php
$db = JFactory::getDBO();
$db->setQuery("SELECT name FROM jos_users INNER JOIN jos_eventlist_register ON jos_users.id = jos_eventlist_register.uid");
$availables = $db->loadObjectList();
foreach ($availables as $available) {
  echo ('<option value="' . $available->id . '">' . $available->name . '</option>');
}
?>

</select>

<label>	</br><br /><br />13.  </label>
<select name="ten">
<?php
$db = JFactory::getDBO();
$db->setQuery("SELECT name FROM jos_users INNER JOIN jos_eventlist_register ON jos_users.id = jos_eventlist_register.uid");
$availables = $db->loadObjectList();
foreach ($availables as $available) {
  echo ('<option value="' . $available->id . '">' . $available->name . '</option>');
}
?>

</select>

<label>	</br><br /><br />14.  </label>
<select name="eleven">
<?php
$db = JFactory::getDBO();
$db->setQuery("SELECT name FROM jos_users INNER JOIN jos_eventlist_register ON jos_users.id = jos_eventlist_register.uid");
$availables = $db->loadObjectList();
foreach ($availables as $available) {
  echo ('<option value="' . $available->id . '">' . $available->name . '</option>');
}
?>
</select>

</br><br /><br /><form name="form1" method="post" action="">
  <input type="submit" name="submit" id="submit" value="Submit">
</form>
Hope somebody can help,


Thanks in advance

Mark
GreyHead 15 Mar, 2009
Hi dyerdyerdyer,

I'm not clear what is happening here. I can see that you select an event from the first drop-down - then each of the others seems to offer you a list of all the players (they are identical I think so there is no need to repeat the database look up each time).

When the form is submitted this will give you an event and a list of players . . . all of whom could be the same person?

I'm not clear where the selection takes place - here? or has it already happened? There is nothing here to link players to an event that I can see.

Bob

PS Also you are only selecting 'name' from the database table so I don't think that $available->id will have a value.
dyerdyerdyer 15 Mar, 2009
Hi Bob

I'm not clear where the selection takes place - here? or has it already happened? There is nothing here to link players to an event that I can see.


I want the selection to be carried out here. All of the players listed are the users that have registered to the event selected in the first drop down list.

When the form is submitted this will give you an event and a list of players . . . all of whom could be the same person?
The Event has already been created and users/players have already registered. Whilst I could have many users/players registering only 14 players can actually go to the event. I want this form to let the users know who has been selected. I know my drop down list at the moment allows the same user/player to be selected more than one time, ideally i wouldn't want this but at the moment its not a priority.

I hope this gives you a better understanding of what im trying to do? 😶
Hope you can still help

Thanks

Mark
GreyHead 15 Mar, 2009
Hi Mark,

You need to do this in two stages. The easy way is to have a two step form. In step 1 you select the event; in step 2 you display the team selection for just that event.

Otherwise you have to load all the possible selections for all the events and use JavaScript to change the options in the dropdowns once the event is selected.

There's also a compromise which is that you use an AJAX driven form that starts out with just the event selector, and once a selection is made the AJAX gets the list of registered players for that event an displays the dropdowns.

Bob

PS Thinking about it, it might be simpler to use checkboxes than drop-downs - and put two checkboxes by each name for player and substitute, but the dropdowns will work OK.
dyerdyerdyer 15 Mar, 2009
Thanks Bob

Couple of questions

If I created a two step form, how would I execute the sql statement that returns the registered users of that event once the user has chosen a fixture?

I like the sound of check boxes but i don't know how I would display a list of the users and then give the option as to whether they are a sub or playing. In terms of my team_selection table where im hoping to store the data, im assuming if i used checkboxes would both fields 'starting' and 'sub' be boolean?

Thanks

Mark
GreyHead 16 Mar, 2009
Hi Mark,

You can create a two-step form using some php in the form html
<p>Team Selection</p>
<?php
$db =& JFactory::getDBO();
$event_id = JRequest('somefield', '', 'post');
if ( !$event_id) {
  // no event has been selected
?>
  <label>Choose Fixture  </label>
  <select name="somefield" >
<?php
  $query = "
    SELECT id, title 
    FROM `#__eventlist_events` 
    WHERE dates > CURDATE(); ";
  $db->setQuery($query);
  $events = $db->loadObjectList();
  foreach ($events as $event) {
    echo '<option value="'.$event->id.'">'.$event->title.'</option>';
  }
?>
  </select>
  <input type='hidden' name='step' value='select_event' />
<?php
} else {
  // an event has been selected
}
?>

<p><br />Starting Eleven</p>
<?php
  $query = "
    SELECT id, name 
      FROM `#__users`
        INNER JOIN` #__eventlist_register` ON #__users.id = #__eventlist_register.uid
    ";
  $db->setQuery($query);
  $availables = $db->loadObjectList();
 $player_options = ""
  foreach ($availables as $available) {
      $player_options .= '<option value="'.$available->id.'">'.$available->name.'</option>';
  }
  $player_options .= "</select>";
  echo "<div>Players</div>";
  for ( $i = 1; $i <= 11; $i++ ) {
    echo "<div><label>$i.  </label></br><select name='player[]'>$player_options</div>";
  }
  echo "<div>Substitutes</div>";
  for ( $i = 1; $i <= 3; $i++ ) {
    echo "<div><label>$i.  </label></br><select name='sub[]'>$player_options</div>";
  }
?>
  <input type='hidden' name='step' value='select_players' />
<?php
}
?>
<input type='submit' name='submit' value='Submit'>


And in the OnSubmit before box (with emails turned On in the General Tab)
<?php
if ( JRequest::getString('step', '', 'post') == 'select_event' ) {
  // if this was returned from Step 1 show the form again
  $showform($post);
  $error_found = true;
}
?>

NB Not tested and will need debugging

This version will return you two arrays - one of player ids and the other of substitute ids. You could do some simple server-side validation to check that these arrays have the correct number of unique entries.

Bob
dyerdyerdyer 16 Mar, 2009
Thanks for the code Bob,

Ive started trying it out and at the moment im receiving the error ,

Parse error: syntax error, unexpected T_FOREACH in C:\xampp\htdocs\Joomla\components\com_chronocontact\chronocontact.html.php(83) : eval()'d code on line 39

I've tried looking at other cases with a T_FOREACH error but cant quite understand what is wrong.

any ideas?


As always, much appreciated.


Mark
GreyHead 16 Mar, 2009
Hi Mark,

I missed the final ; off line 38 should be
$player_options = "";

Bob
dyerdyerdyer 16 Mar, 2009
ok im now getting this error

Fatal error: Call to undefined function JRequest()

which corresponds to this line

$event_id = JRequest('somefield', '', 'post');

I think im right in believing 'somefield' should be changed to the field that currently holds the title of every event? would this be correct? As when ive changed 'somefield' to 'title', but i get the above error.


Mark
GreyHead 16 Mar, 2009
Hi dyerdyerdyer,

Apologies, getting post overload here. Make that
$event_id = JRequest::getVar('somefield', '', 'post');

Bob
dyerdyerdyer 17 Mar, 2009
Hi again

Im now getting the following error although i dont think there is anything obviously missing

Warning: Invalid argument supplied for foreach() in /home2/guru21/public_html/components/com_chronocontact/chronocontact.html.php(83) : eval()'d code on line 39,

Any ideas bob?

Thanks

Mark
GreyHead 17 Mar, 2009
Hi Mark,

It's not finding any availalbles.

Echo the query out and paste into into PHPMyAdmin to see what is happening.
Add
echo "query: ".print_r($query, true)."<br /><br />";
after the query and it should echo to the screen.

Bob
dyerdyerdyer 23 Mar, 2009
Hi Bob

Ive been away for the past week and haven't been online. In regards to not being able to find any availables, is it the 2nd query that should be showing results? I have been trying to use your echo code to print the result of the query out but at the moment, it doesn't return anything although im not 100% sure im putting the line in the right place. Also testing both queries in phpmyadmin, im having to change any references to tables, for example #__eventlist_register to jos_eventlist_register, just to understand, what is the reason for you changing this as i dont know why? 🙂


As always, I appreciate your help

Thanks


Mark
Max_admin 23 Mar, 2009
Hi Mark,

does it return results when you do it in phpmyadmin ?

the #__ is replaced by the "jos_" or whatever database prefix through Joomla code!

Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 23 Mar, 2009
Hi Mark,

The echo line should go immediately after the $query = ". . . ."; - make sure that you do not have a ReDirect URL set and the information should print to the screen.

Bob

PS As Max says the #__ is the standard Joomla table prefix - 95% of the time it is replaced by jos_ but I try to cover the more general case in the forum posts just in case someone else trie sit and it doesn't work. If you use the EasySQL extension it will make the change for you.
dyerdyerdyer 23 Mar, 2009
Hi

Thanks for both of your help,

there was a problem with the query and i have sorted it now. I can now select a fixture and players. url is here

The problem im having now is that, the drop down lists for the players don't seem dependent on what fixture is chosen. From the drop down list, you can see that the name Mark Dyer appears twice, that is because he is available for both fixtures that can be chosen. Im sorry Bob if I didn't explain this clear at the start 😶 , but ideally I would like just the players that are available for each event rather than listing all players that are available to all events.

Can this be done?

here is my latest code just in case i have missed something AGAIN lol.
<p>Team Selection</p>
    <?php
    $db =& JFactory::getDBO();
    $event_id = JRequest::getVar('somefield', '', 'post');
    if ( !$event_id) {
      // no event has been selected
    ?>
      <label>Choose Fixture  </label>
      <select name="somefield" >
    <?php
      $query = "
        SELECT id, title
        FROM `jos_eventlist_events`
        WHERE dates > CURDATE(); ";
      $db->setQuery($query);
      $events = $db->loadObjectList();
      foreach ($events as $event) {
        echo '<option value="'.$event->id.'">'.$event->title.'</option>';
      }
    ?>
      </select>
      <input type='hidden' name='step' value='select_event' />
    <?php
    } else {
      // an event has been selected
    }
    ?>

    <p><br />Starting Eleven</p>
    <?php
      $query = "
SELECT jos_users.id, name
FROM jos_users
INNER JOIN jos_eventlist_register ON jos_users.id = jos_eventlist_register.uid
        ";
      $db->setQuery($query);
      $availables = $db->loadObjectList();
    $player_options = "";
      foreach ($availables as $available) {
          $player_options .= '<option value="'.$available->id.'">'.$available->name.'</option>';
    
}
	   
      $player_options .= "</select>";
      echo "<div>Players</div>";
      for ( $i = 1; $i <= 11; $i++ ) {
        echo "<div><label>$i.  </label></br><select name='player[]'>$player_options</div>";
      }
      echo "<div>Substitutes</div>";
      for ( $i = 1; $i <= 3; $i++ ) {
        echo "<div><label>$i.  </label></br><select name='sub[]'>$player_options</div>";
      }
    ?>
      <input type='hidden' name='step' value='select_players' />
    <?php
    
    ?>
    <input type='submit' name='submit' value='Submit'>

Sorry if i havent made myself clear, ask questions if im not

Thanks again

Mark
GreyHead 23 Mar, 2009
Hi Mark,

True - see this post from earlier in the thread - I don't think that question was ever answered. Which way do you want to go, 2-step form or JavaScript?

Bob
dyerdyerdyer 23 Mar, 2009
Ah right for some reason, I thought your suggested code was a two stage form, my knowledge lacks so much. Which would be easier now that we have this much code already? How much would need to be changed?


Thanks

Mark
dyerdyerdyer 24 Mar, 2009
Hi Bob

Do you think this could be changed easily into a two stage form or would JavaScript be easier? Would the whole code need to be re-wrote?

Thanks

Mark
Max_admin 25 Mar, 2009
Hi Mark,

I know bob is very busy now, the 2 different methods will work for your form, but each method has its own benefits/issues, please look at the forums because Bob posted that before, if you can wait few days then maybe a new plugin will come out which supports multi page forms, I'm working on this!

Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 25 Mar, 2009
Hi Mark,

Apologies, I'm about to go away for a week and have been rushing around trying to get a lot of client stuff finished. One of the side effects is that posts here that will take more than a few minutes to answer get left. Hopefully I'll have more time when I'm back again.

Bob
dyerdyerdyer 25 Mar, 2009
Hi Bob

Not a problem, speak to you in a week


Mark
dyerdyerdyer 02 Apr, 2009
Hi Bob

Here is my problem that you have been helping me with. If there any questions just ask. I need your advice and help on whether javascript or a two step form will help with my problem

thanks

Mark
GreyHead 09 Apr, 2009
Hi Mark,

Sorry for the long delay - everything seems to have got very busy :-(

Looking at this again I think a 2-step form will do the job very well. So please try this code
<p>Team Selection</p>
<?php
$db =& JFactory::getDBO();
$event_id = JRequest::getVar('event', '', 'post');
if ( !$event_id) {
      // no event has been selected
?>
    <label>Choose Fixture  </label>
    <select name="event" >
<?php
    $query = "
        SELECT id, title
            FROM `jos_eventlist_events`
            WHERE dates > CURDATE(); ";
    $db->setQuery($query);
    $events = $db->loadObjectList();
    foreach ($events as $event) {
        echo '<option value="'.$event->id.'">'.$event->title.'</option>';
    }
?>
    </select>
    <input type='hidden' name='step' value='select_event' />
<?php
} else {
    // an event has been selected
?>
    <p><br />Starting Eleven</p>
<?php
    $query = "
        SELECT `#__users`.`id`, `name`
            FROM `#__users`
            INNER JOIN `#__eventlist_register` ON `#__users`.`id` = `#__eventlist_register`.`uid`
            WHERE `#__eventlist_register`.`id` = ".$d->Quote($event_id)." ; 
        ";
    $db->setQuery($query);
    $availables = $db->loadObjectList();
    $player_options = "";
    foreach ( $availables as $available ) {
        $player_options .= '<option value="'.$available->id.'">'.$available->name.'</option>';
    }
    $player_options .= "</select>";
    echo "<div>Players</div>";
    for ( $i = 1; $i <= 11; $i++ ) {
        echo "<div><label>$i.  </label></br><select name='player[]'>$player_options</div>";
    }
    echo "<div>Substitutes</div>";
    for ( $i = 1; $i <= 3; $i++ ) {
        echo "<div><label>$i.  </label></br><select name='sub[]'>$player_options</div>";
    }
?>
    <input type='hidden' name='step' value='select_players' />
<?php
}
?>
<input type='submit' name='submit' value='Submit'>

and in the OnSubmit Beforebox (with Emails turned on)
<?php
$step = JRequest::getVar('step', '', 'post');
if ( $step == 'select_event' ) {
    showform($_POST);
    $error_found = true;
}
//  team processing here
?>

Note: not tested and may need debugging!!

Bob
dyerdyerdyer 09 Apr, 2009
Hi Bob

Thanks for the reply, at the moment it fails on line 33

WHERE `#__eventlist_register`.`id` = ".$d->Quote($event_id)." ;

error im receiving is

"Call to a member function Quote() on a non-object in C:\xampp\htdocs\Joomla\components\com_chronocontact\chronocontact.html.php(83) : eval()'d code on line 33"

I understand to logic but dont know why it isnt working, are we missing something obvious
GreyHead 09 Apr, 2009
Hi Mark,

Should be $db->Quote( . . . missed the 'b'

Bob
dyerdyerdyer 09 Apr, 2009
Hi Bob

The two step form is now working, i can select a fixture and the possibility to select a starting line up is present although i can no longer see any users that are associated to that fixture in my drop down list. Whilst it works it doesnt appear to list the members that are available to that fixture.

I'm assuming that the drop down lists are no longer linked to the fixture that is chosen?

web address is http://wtfc.nxserve.net/index.php?option=com_chronocontact&chronoformname=team

To the left of the form, you can see a 'Next Fixture' plugin which if you click book now you can see that there are two users associated to that fixture..

Hope this helps?
maybe its just something that you have left out? i don't know

Thanks as always

Mark
GreyHead 09 Apr, 2009
Hi Mark,

Most likely there is something wrong with the sql query that selects the players. Check this out with PHPMyAdmin and see what you need to get the right result.

Bob
dyerdyerdyer 09 Apr, 2009
Hi Bob

Thanks for your help, ive managed to fix the sql problem, the below statement changed from

SELECT `jos_users`.`id`, `name`
FROM `jos_users`
INNER JOIN `jos_eventlist_register` ON `jos_users`.`id` = `jos_eventlist_register`.`uid`
WHERE `jos_eventlist_register`.`id` = ".$db->Quote($event_id)." ;

to

SELECT `jos_users`.`id`, `name`
FROM `jos_users`
INNER JOIN `jos_eventlist_register` ON `jos_users`.`id` = `jos_eventlist_register`.`uid`
WHERE `jos_eventlist_register`.`event` = ".$db->Quote($event_id)." ;

and now it works.

My last request is after selecting a side and pressing submit, how do i send the side that has been selected to every users email address on my site? can this be done? also is there a way that i can save the form and the side that has been selected as an article?


Thanks Bob, im almost there
GreyHead 09 Apr, 2009
Hi Mark,

Glad it 's working !

Max posted some mailer code like this a week or so ago.

Bob
dyerdyerdyer 14 Apr, 2009
Hi Bob

The form is working great, im now getting emails sent from the form. The email response displays the players selected but displays them using their Id number rather than their name. Ive tried a couple of searches looking for Max's mailer code and whilst I have found a couple of threads, i still don't know how i'm meant to alter the email template so that rather than their id's being displayed its their name. Any ideas?, I was wondering whether it would be something that would need to be changed in the original code rather than in the email template. Hope you can help,


Thanks in advance


Mark
Max_admin 14 Apr, 2009
Hi Mark,

I'm not following this from the beginning but, whats your email template ? how does your code work now ?

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
dyerdyerdyer 14 Apr, 2009
Hi,

If my email template is switched off, i get the following email,

event
step select_players
player 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69
sub 69, 69, 69
submit Submit


Submitted by

My form basically lets me choose particular users for an event, because im testing i just choose the same user for every position for the event, hence the 69s lol concidence honest. The 69 represents a users id in a table. When I choose the users that go with the event, im choosing names raher than ids but the email shows id's

My template looks as follows,

<p>Tartan Players,</p> <br/><br/>

<p>Like always, our next game requires huge commitment and effort, and is the least I expect. Below is the squad for the following fixture.</p> <br/><br/>


**********List of Names, rather than id''s*********************


<p>As always full support is needed, I'd like to see as many of you down at the ground as possible. </p> <br/><br/>

<p>Thanks</p> <br/><br/>

<p>Gaffer</p>

Ideally I would like the email to display the name of the user rather than his id. The position of where I would like to display the list is shown by the ********** 🙂 . If it is possible I would also like the fixture/event that goes with the list of players to be displayed.

I just dont know how to convert the id to names, in the email template

Thanks

Mark
Max_admin 15 Apr, 2009
Hi Mark,

Actually

**********List of Names, rather than id''s*********************

will have something to be changed to fix this so I need to see this code🙂

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 15 Apr, 2009
Hi Mark,

I see what's happening. We have the list of ids because that's what you need to save in the database. They need to be converted back to usernames again. Without seeing all of the code in front of me I find it hard to put together. It may be that the info is already in the post array - if not, then a database lookup in the OnSubmit before box or in the Email template itself would give you the values that you need.

Bob
dyerdyerdyer 15 Apr, 2009
Hi Bob

Thankyou for your reply, here is the code as it stands,

Form Html

  <p>Team Selection</p>
    <?php
    $db =& JFactory::getDBO();
    $event_id = JRequest::getVar('event', '', 'post');
    if ( !$event_id) {
          // no event has been selected
    ?>
        <label>Choose Fixture  </label>
        <select name="event" >
    <?php
        $query = "
            SELECT id, title
                FROM `jos_eventlist_events`
                WHERE dates > CURDATE(); ";
        $db->setQuery($query);
        $events = $db->loadObjectList();
        foreach ($events as $event) {
            echo '<option value="'.$event->id.'">'.$event->title.'</option>';
        }
    ?>
        </select>
        <input type='hidden' name='step' value='select_event' />
    <?php
    } else {
        // an event has been selected
    ?>
        <p><br />Starting Eleven</p>
    <?php
        $query = "
            SELECT `jos_users`.`id`, `name`
                FROM `jos_users`
                INNER JOIN `jos_eventlist_register` ON `jos_users`.`id` = `jos_eventlist_register`.`uid`
                WHERE `jos_eventlist_register`.`event` = ".$db->Quote($event_id)." ;
            ";
        $db->setQuery($query);
        $availables = $db->loadObjectList();
        $player_options = "";
        foreach ( $availables as $available ) {
            $player_options .= '<option value="'.$available->id.'">'.$available->name.'</option>';
        }
        $player_options .= "</select>";
        echo "<div>Players</div>";
        for ( $i = 1; $i <= 11; $i++ ) {
            echo "<div><label>$i.  </label></br><select name='player[]'>$player_options</div>";
        }
        echo "<div>Substitutes</div>";
        for ( $i = 1; $i <= 3; $i++ ) {
            echo "<div><label>$i.  </label></br><select name='sub[]'>$player_options</div>";
        }
    ?>
        <input type='hidden' name='step' value='select_players' />
    <?php
    }
    ?>
    <input type='submit' name='submit' value='Submit'>

On Sumbit code

<?php
$step = JRequest::getVar('step', '', 'post');
if ( $step == 'select_event' ) {
    showform($_POST);
    $error_found = true;
}
//  team processing here
?>


I think i understand the logic of the code in "on Submit code" but the line "showform($_POST) i believe is calling a method called POST? Except I dont see the method in the form html. From this code can you determine whether the info is already in the array, or a database lookup needs to be in either the on submit or email template?

Thanks as always


Mark
GreyHead 16 Apr, 2009
Hi Mark,

$_POST is PHP-speak for the from results array. You can see it displayed if you turn DeBug on in the ChronoForms General Tab and submit a form. What it does here is to make sure that the previous results are available when the form is re-displayed.

Bob

PS Using $_POST isn't very good Joomla as the results are unfiltered. I should perhaps use JFactory::get('post') instead.
dyerdyerdyer 17 Apr, 2009
Hi Bob

This is what the debug returned

_POST: Array ( [event] => 8 [step] => select_event [submit] => Submit )
Case 2: Use template

Followed by

_POST: Array ( [player] => Array ( [0] => 65 [1] => 65 [2] => 65 [3] => 65 [4] => 65 [5] => 65 [6] => 65 [7] => 65 [8] => 65 [9] => 65 [10] => 65 ) [sub] => Array ( [0] => 65 [1] => 65 [2] => 65 ) [step] => select_players [submit] => Submit )
Case 2: Use template
E-mail: 'Yes' custom
Email sent

Followed by my email template

does this help with assistance to converting the id's to names in the email?

Thanks

Mark
GreyHead 17 Apr, 2009
Hi Mark,

Try this in the OnSubmit Before box
<?php
$players = JRequest::getVar('players', '', 'post');
$player_list = implode(', ', $players);
$db = & JFactory::getDBO();
$query = "
  SELECT name
    FROM `#__users`
    WHERE `id` IN ($player_list);
";
$db->Quote($query);
$player_names = explode(', ', $db->loadResultArray());
?>

You'd then need to repeat essentially similar code to get the sub names.

To add then into the email you can either add PHP snippets to echo $player_names; or add a hidden player_names field to the form and update the results with:
JRequest::setVar('player_names', $player_names, 'post');

Bob
dyerdyerdyer 17 Apr, 2009
Hi Bob

Sorry to sound dumb, but if I was to implement a hidden field name where would it go? and would $players_name simply be a sql statement? would it be located somewhere below this

<p><br />Starting Eleven</p>
    <?php
        $query = "
            SELECT `jos_users`.`id`, `name`
                FROM `jos_users`
                INNER JOIN `jos_eventlist_register` ON `jos_users`.`id` = `jos_eventlist_register`.`uid`
                WHERE `jos_eventlist_register`.`event` = ".$db->Quote($event_id)." ;
            ";
        $db->setQuery($query);
        $availables = $db->loadObjectList();
        $player_options = "";
        foreach ( $availables as $available ) {
            $player_options .= '<option value="'.$available->id.'">'.$available->name.'</option>';
        }
        $player_options .= "</select>";
        echo "<div>Players</div>";
        for ( $i = 1; $i <= 11; $i++ ) {
            echo "<div><label>$i.  </label></br><select name='player[]'>$player_options</div>";
        }
        echo "<div>Substitutes</div>";
        for ( $i = 1; $i <= 3; $i++ ) {
            echo "<div><label>$i.  </label></br><select name='sub[]'>$player_options</div>";
        }
    ?>
        <input type='hidden' name='step' value='select_players' />


Thanks

Mark
GreyHead 17 Apr, 2009
Hi Mark,

That's Ok for the hidden field - it just creates a place-holder so that ChronoForms knows that there is some data to come.

The the JRequest::setVar . . . can go after the other code in the OnSubmit Befors box (but inside the <?php . . ?> php tags like
. . .
$db->Quote($query);
$player_names = explode(', ', $db->loadResultArray());
JRequest::setVar('player_names', $player_names, 'post');
?>

Bob
dyerdyerdyer 17 Apr, 2009
Hi Bob

After implementing your latest code my form looks like this

<p>Team Selection</p>
    <?php
    $db =& JFactory::getDBO();
    $event_id = JRequest::getVar('event', '', 'post');
    if ( !$event_id) {
          // no event has been selected
    ?>
        <label>Choose Fixture  </label>
        <select name="event" >
    <?php
        $query = "
            SELECT id, title
                FROM `jos_eventlist_events`
                WHERE dates > CURDATE(); ";
        $db->setQuery($query);
        $events = $db->loadObjectList();
        foreach ($events as $event) {
            echo '<option value="'.$event->id.'">'.$event->title.'</option>';
        }
    ?>
        </select>
        <input type='hidden' name='step' value='select_event' />
    <?php
    } else {
        // an event has been selected
    ?>
        <p><br />Starting Eleven</p>
    <?php
        $query = "
            SELECT `jos_users`.`id`, `name`
                FROM `jos_users`
                INNER JOIN `jos_eventlist_register` ON `jos_users`.`id` = `jos_eventlist_register`.`uid`
                WHERE `jos_eventlist_register`.`event` = ".$db->Quote($event_id)." ;
            ";
        $db->setQuery($query);
        $availables = $db->loadObjectList();
        $player_options = "";
        foreach ( $availables as $available ) {
            $player_options .= '<option value="'.$available->id.'">'.$available->name.'</option>';
        }
        $player_options .= "</select>";
        echo "<div>Players</div>";
        for ( $i = 1; $i <= 11; $i++ ) {
            echo "<div><label>$i.  </label></br><select name='player[]'>$player_options</div>";
        }
        echo "<div>Substitutes</div>";
        for ( $i = 1; $i <= 3; $i++ ) {
            echo "<div><label>$i.  </label></br><select name='sub[]'>$player_options</div>";
        }
    ?>
        <input type='hidden' name='step' value='select_players' />
        <input type='hidden' name='player_names' value='' />
    <?php
    }
    ?>
    <input type='submit' name='submit' value='Submit'>


On Submit

<?php
$players = JRequest::getVar('players', '', 'post');
$player_list = implode(', ', $players);
$db = & JFactory::getDBO();
$query = "
  SELECT name
    FROM `jos_users`
    WHERE `id` IN ($player_list);
";
$db->Quote($query);
$player_names = explode(', ', $db->loadResultArray());
JRequest::setVar('player_names', $player_names, 'post');
?>


email template

<p>Tartan Players,</p> <br/><br/>

<p>Like always, our next game requires huge commitment and effort, and is the least I expect. Below is the squad for the following fixture.</p> <br/><br/>

{player_names}




<p>As always full support is needed, I'd like to see as many of you down at the ground as possible. </p> <br/><br/>

<p>Thanks</p> <br/><br/>

<p>Gaffer</p>


The problem im having now is that after picking the fixture in the first stage of the form, the second stage which allows me to choose players no longer displays. Can you see anything that we have changed which has resulted in the second stage of the form no longer displaying? if you would like to try the form is located here. http://markdyer.info/index.php?option=com_chronocontact&chronoformname=selection

Thanks as always

Mark
GreyHead 17 Apr, 2009
Hi mark,

At a quick look I think that you've removed the old code from the OnSubmit box, that needs to stay. The new code is additional.

Bob
dyerdyerdyer 17 Apr, 2009
Hi Bob

here is the code that i believe now works

<?php
$step = JRequest::getVar('step', '', 'post');
if ( $step == 'select_event' ) {
    showform($_POST);
    $error_found = true;
}
//  team processing here
$players = JRequest::getVar('players', '', 'post');
$player_list = implode(', ', $players);
$db = & JFactory::getDBO();
$query = "
  SELECT name
    FROM `jos_users`
    WHERE `id` IN ($player_list);
";
$db->Quote($query);
$player_names = explode(', ', $db->loadResultArray());
JRequest::setVar('player_names', $player_names, 'post');
?>


Whilst you stated that I needed to put {player_names} in my email template, will that list all of the names, or would i need to duplicate {player_names} so many times?


Thanks

Mark
GreyHead 17 Apr, 2009
Hi Mark,

It should list all the player names (you'll need second one for the subs list). Try it and see what happens?

Bob
dyerdyerdyer 17 Apr, 2009
Hi Bob

At the moment, this is my email template
<p>Tartan Players,</p> <br/><br/>

<p>Like always, our next game requires huge commitment and effort, and is the least I expect. Below is the squad for the following fixture.</p> <br/><br/>

{player_names}




<p>As always full support is needed, I'd like to see as many of you down at the ground as possible. </p> <br/><br/>

<p>Thanks</p> <br/><br/>

<p>Gaffer</p>


Im receiving everything except the players names, i think i have something obvious missing 😶

Thanks

Mark
GreyHead 17 Apr, 2009
Hi Mark,

The easiest thing at this stage is for me to take a look - I loose track of all the otehr steps each time. If it's OK with you please email or PM me a SuperAdmin login and I'l see what's missing.

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