Project:Webform
Version:5.x-1.9
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

hi, I'm trying to setup a webform with select components so a user will register to an event.

I don't want to use the signup module because of 2 main reasons: 1. I can't limit the # of Events a user can register at the same time and 2. using hidden components I can show the user's profile in the same table without coding...

Bassically what I need is a php script (I guess) that does the following:

Count the available sits on each of the select options to prevent a user registers to an Event that is Full.

for the first option the query will look like this: select count('data') from webform_submitted_data where data='Event 1'. If the query result is 150 and the available sits are 150 "Event 1" option will be disabled OR a user will get an Error Message saying "Event is Full".

This will be for each of the different options, all of them have different available sits.

I guess I can do this in the Additional Validation or Additional Processing Settings but the problem is my php skills, I've been reading lots of docs but nothing.

thanks in advance. any help will be appreciated.

Luis

Comments

#1

Title:little help with php and webform» help with webform validation

I've been trying to solve this but I it's not working. I'm using this code after 1 day of research

<?php
  $mydata
= $form_values['event']; //gets the event selected
 
$query = db_result(db_query("SELECT count(data) FROM webform_submitted_data WHERE data='$mydata'"));
 
$query_result = print ($query);
    if (
$query_result >= 2) { // "2" is the event's limit
   
form_set_error('', t('Select another event'));
}
?>

I get a WSOD with a 0 and no error is showing and the form saves the data in the database anyway.

What I'm trying to do is setting up a limit to an event, (using webform and checkbox component), to prevent a user from selecting an event with no seats available. I'm using the query to know how many users registered to the event selected in $mydata and if the limit has been reached the user gets an error message and he/she has to select another option.

What am I doing wrong? Any help?

Thanks

Luis

#2

Here's the solution I've found:

I'll try to explain myself, as I didn't have php experience.

First, I had to validate the submitted value to know how many times this value was submitted before, to do so, I used the next query:

$query = db_result(db_query("SELECT count(data) FROM webform_submitted_data WHERE data='$mydataevent'"));

The variable $mydataevent it's equal to the submitted value on the webform. But I had a problem with this, it seems that for some reason, $form_values['submitted_tree']['event']; was formatting the name of my event from "Event Name" to "event_name". I didn't know why, so I had to format it back to "Event Name".

$mydataevent=$form_values['submitted_tree']['event'] ;

To do it, I used switch ($mydataevent) and defined every case and specified a new variable called $maxlimit, which is the Limit of the Selected Event.

After this I just wrote an if to know if my query was greater than the maxlimit.

Here's the code.

<?php
  $mydataevent
=$form_values['submitted_tree']['event'] ;
 
switch (
$mydataevent) {
   
    case
'taller_intercultural_administration':
   
$mydataevent='Taller Intercultural Administration ';
   
$maxlimit = 45;
    break;
  
    case
'taller_el_juego_de_la_cerveza':
   
$mydataevent='Taller El juego de la cerveza';
   
$maxlimit= 45;
    break;
       
  }

 
$query= db_result(db_query("SELECT count(data) FROM webform_submitted_data WHERE data='$mydataevent'"));
    if (
$query>= $maxlimit) {
   
form_set_error('$query', t('Event is Full.'));
}

?>

Hope it helps somebody else.

Luis

#3

Status:active» fixed

just to change the status

#4

Thanks for sharing lelizondob!

#5

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.