• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: limit given choices [SOLVED]

limit given choices [SOLVED] 10 years 7 months ago #24662

  • hans2103
  • hans2103's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 9
  • Thank you received: 6
Hi,

I want to limit the choices of a radiobox group if an item is already selected twice

My form
song
  1. 1. song A
  2. 2. song B
  3. 3. song C
  4. 4. song D
  5. 5. song E
  6. 6. song F

name
just in input field
email
just in input field
submit


The PHP script below is called upon form display and limits the submission to a given amount. In this case 11.
$available = 11;
global $database;
$database = JFactory::getDBO();
$database->setQuery("SELECT COUNT(`SubmissionId`) FROM #__rsform_submissions WHERE `formId`='4'");
$database->query();
if (intval($database->loadResult()) < $available) {
  $places = $available - intval($database->loadResult());
  if ($places == 1) {
    echo '<div class="alert alert-warning">';
    echo 'Er is nog één beschikbaar';
    echo '</div>';
  } else {
    echo '<div class="alert alert-success">';
    echo 'Er zijn nog ' . $places . ' plaatsen beschikbaar';
    echo '</div>';
  }
} else {
  echo '<div class="alert alert-error">';
  echo 'Er zijn geen plaatsen meer beschikbaar';
  echo '</div>';
  $formLayout = '';
}

But there's another restriction.
Every song can just be selected twice. Only two submissions are allowed the same song. When a song is submitted for the second time it has to be disabled.
But how?

I can count the amount of submissions of a song using the following SQL statement:
SELECT FieldValue, COUNT( * ) 
FROM  `#_rsform_submission_values` 
WHERE FormID =4
AND FieldName =  'song'
GROUP BY FieldValue

converted into PHP code for RSForms:
global $database;
$database = JFactory::getDBO();
$database->setQuery("SELECT `FieldValue`, COUNT( * ) FROM `#_rsform_submission_values` WHERE `FormID`='4' AND `FieldName`='song' GROUP BY `FieldValue`");
$database->query();

und jetzt?
what's next?
en nu?

How can I restrict the choices of songs?
How can I disable some rows of the radio box group?
Last Edit: 10 years 7 months ago by hans2103.
The administrator has disabled public write access.
The following user(s) said Thank You: nahrafqifahs, werner04

limit given choices [SOLVED] 10 years 7 months ago #24677

  • hans2103
  • hans2103's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 9
  • Thank you received: 6
combining my solution with the RSForms tutorial on auto populate a list from a table I was able to solve my issue.

I created a new table with songs
id, year, songid songtitle
1,2013,201301,song A
2,2013,201302,song B
3,2013,201303,song B
4,2013,201304,song B
5,2013,201305,song B

I'm able to create a list using the tutorial from the link above:
//<code>
$items = array();
global $database;
$database = JFactory::getDbo();
$database->setQuery("SELECT songID,songtitle FROM songs WHERE year=2013");
$results = $database->loadObjectList();
foreach ($results as $result) {
  $songID = $result->songID;
  $song = $result->songtitle;
  $items[] = $songID.'|'.$songtitle;
}
$items = implode("\n", $items);
return $items;
//</code>


This will create a list and when you select a radio button the value will be stored in the database. When you select song A, the value 201301 will be stored.
The next step is the combination of my SQL statement of my previous post and the SQL statement in the command above.
SELECT 
  songID,song 
FROM songs 
 LEFT JOIN (
  SELECT FieldValue, COUNT( * ) AS count 
  FROM `#_rsform_submission_values` 
  WHERE FormID =4 AND FieldName = 'song' 
  GROUP BY FieldValue
) L ON titleID = FieldValue 
WHERE year = 2013 AND (count IS NULL OR count < 2);

I combine the results of a calculation of the submitted songs as a restriction to the selected song and songID.


I've copied and pasted the following code in field "items" of the radio box.
//<code>
$items = array();
global $database;
$database = JFactory::getDbo();
$database->setQuery("SELECT `titleID`,`title` FROM `o8iov_rsform_custom_keinderkwek` LEFT JOIN (SELECT `FieldValue`, COUNT( * ) AS `count` FROM `o8iov_rsform_submission_values` WHERE `FormID`='4' AND `FieldName`='keuzelijst' GROUP BY `FieldValue`) L ON `titleID`=`FieldValue` WHERE `year`='2013' AND (`count` IS NULL OR `count` < '2')");
$results = $database->loadObjectList();
foreach ($results as $result) {
  $titleID = $result->titleID;
  $title = $result->title;
  $items[] = $titleID.'|'.$title;
}
$items = implode("\n", $items);
return $items;
//</code>

when you submit song A twice it will be deleted from the list.
and... there are just 9 (11 - 2) submissions left.
The administrator has disabled public write access.
The following user(s) said Thank You: nahrafqifahs, werner04

limit given choices [SOLVED] 3 years 9 months ago #40306

  • nahrafqifahs
  • nahrafqifahs's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
  • Thank you received: 1
Wow, bro!! After 6 years!!

Bro, your solution help me!!

THANK YOU!!
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!