Thanks for such an awesome Joomla add-on. This component is so cool and its uses are endless! The support here is great on the forums - I have browsed many times here to solve problems.
Here is what I want to do - which is probably very easy - but not much of a coder... I am running Joomla 1.0, CB, and latest Chrono utilizing profile plugin.
I have an event registration page for registered users. I want to prevent users from submiting (registering) multiple times. I am pulling user info into readonly inputs using the profile plugin - including their userid. If a user goes to the event registration form and there is already a record for that user in the forms table - I would want that user to be redirect to a "already registered" page.
Any ideas?
Here is what I want to do - which is probably very easy - but not much of a coder... I am running Joomla 1.0, CB, and latest Chrono utilizing profile plugin.
I have an event registration page for registered users. I want to prevent users from submiting (registering) multiple times. I am pulling user info into readonly inputs using the profile plugin - including their userid. If a user goes to the event registration form and there is already a record for that user in the forms table - I would want that user to be redirect to a "already registered" page.
Any ideas?
Hi gjr,
At the beginning of your form you'll need to check their id, then lookup the event table. If they are already registered show a message, otherwise show the form.
Bob
At the beginning of your form you'll need to check their id, then lookup the event table. If they are already registered show a message, otherwise show the form.
Bob
Thanks Bob - Not much of a coder - any chance you could post some code hints?🙂
Most likely not the best solution, but it is working for me. In the form code block I put:
Where #__chronoforms1 is your generated table...;)
<?php
global $database, $my;
$CurrUID = $my->id;
$database->setQuery( "SELECT * FROM #__chronoforms_1 ".
"WHERE UserID=$CurrUID" );
$registered = $database->loadObjectList();
if ( count( $registered ) ) {
//Already Registered Action
}
else {
//Event Registration Form
} ?>
Where #__chronoforms1 is your generated table...;)
Hi, im looking for this same functionality however my form has php in it and is pretty long.
How can I hide the form if someone has already submitted and show it if they haven't?
ps. (thanks bob/max for your previous efforts and help with my form...It's going down a treat!)
How can I hide the form if someone has already submitted and show it if they haven't?
ps. (thanks bob/max for your previous efforts and help with my form...It's going down a treat!)
yes they are logged in. in the form the user id, and username is submitted also so im guessing one of these can be used to check against.
Thanks.
Thanks.
Hi smappler,
Yes make user that you log the user id with the record, then in the form html check the file
Bob
Yes make user that you log the user id with the record, then in the form html check the file
<?php
$user =& JFactory::getUser();
$db =& JFactory::getDBO();
$query = "
SELECT count(*)
FROM `#__some_table`
WHERE `user_id` = ".$db->Quote($user->id).";
";
$db->setQuery($query);
if ( $db->loadResult() ) {
// this user has already responded
// redirect
} else {
// this user hasn't responded
//show the form
}
?>
Not tested and will need debuggingBob
hi bob thanks for the reply.
what do i actually need to have inside the if and else statement? to redirect to another page and to display the form?
thanks.
what do i actually need to have inside the if and else statement? to redirect to another page and to display the form?
thanks.
leave the else empty, add this to redirect:
$mainframe->redirect('index.php', 'you are already signed up!');
Hi there,
Thanks for this thread, this was almost exactly what I needed and I got this to work on my form.
I say "almost" because I need it slightly different. I'm using the plugin to show my form on the bottom of an article.
How do I place my form between the "else" brackets? This is the code untill now:
Note: the name field is automatically filled in and read only.
Most ideal would be a way for the user to unregister in case he has already registered (between the "If" brackets). Is that possible?
Thanks
Thanks for this thread, this was almost exactly what I needed and I got this to work on my form.
I say "almost" because I need it slightly different. I'm using the plugin to show my form on the bottom of an article.
How do I place my form between the "else" brackets? This is the code untill now:
<?php
$my = JFactory::getUser();
?>
<?php
$user =& JFactory::getUser();
$db =& JFactory::getDBO();
$query = "
SELECT count(*)
FROM `jos_chronoforms_Reservatie`
WHERE `cf_user_id` = ".$db->Quote($user->id).";
";
$db->setQuery($query);
if ( $db->loadResult() ) {
echo "this user has already responded";
// redirect
} else {
echo "this user hasn't responded";
//show the form
}
?>
<div class="form_item">
<div class="form_element cf_textbox">
<label class="cf_label" style="width: 150px;">Naam</label>
<input class="cf_inputbox" maxlength="150" size="30" title="" id="naam" name="naam" type="text" value="<?php echo $my->name; ?>" readonly="readonly" />
</div>
<div class="cfclear">Â </div>
</div>
<div class="form_item">
<div class="form_element cf_dropdown">
<label class="cf_label" style="width: 150px;">Aantal</label>
<select class="cf_inputbox validate-selection" id="select_1" size="1" title="" name="aantal">
<option value="">Choose Option</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
</div>
<input value="Verzend" name="undefined" type="submit" />
<div class="cfclear">Â </div>
</div>
Note: the name field is automatically filled in and read only.
Most ideal would be a way for the user to unregister in case he has already registered (between the "If" brackets). Is that possible?
Thanks
Sorry for my previous post but since I am not the most patient guy I kept trying and I got it working this way: (probably not the cleanest coding, I removed the div's for a better overview):
I had to break op the html to get the autofilled namefield working. I'm not sure if I did that the right way but it works like this, aparently.
The only thing left is the unregister button that will delete the users database record. If thats possible.
<?php
$my = JFactory::getUser();
?>
<?php
$user =& JFactory::getUser();
$db =& JFactory::getDBO();
$query = "
SELECT count(*)
FROM `jos_chronoforms_Reservatie`
WHERE `cf_user_id` = ".$db->Quote($user->id).";
";
$db->setQuery($query);
if ( $db->loadResult() ) {
echo "this user has already responded";
// redirect
} else {
echo "<input class='cf_inputbox' maxlength='150' size='30' title='' id='naam' name='naam' type='text' value='";?>
<?php echo $my->name;?>
<?php echo "' readonly='readonly' />
<select class='cf_inputbox validate-selection' id='select_1' size='1' title='' name='aantal'><option value=''>Choose Option</option><option value='1'>1</option><option value='2'>2</option></select>
<input value='Verzend' name='undefined' type='submit' />";
//show the form
}
?>
I had to break op the html to get the autofilled namefield working. I'm not sure if I did that the right way but it works like this, aparently.
The only thing left is the unregister button that will delete the users database record. If thats possible.
Hi mackirony,
No problem, I'm having a slow day here (and it was lunchtime).
That's pretty much how I would have done it I think.
Bob
No problem, I'm having a slow day here (and it was lunchtime).
That's pretty much how I would have done it I think.
Bob
Nono, I know you are lighting fast. You have helped me before ;-)
Is it possible to have a button, when the form is not showing, to unregister? So a button that deletes the record in the database that holds that users reservation?
Is it possible to have a button, when the form is not showing, to unregister? So a button that deletes the record in the database that holds that users reservation?
Hi mackirony,
Not quite sure where you want to put it but 'yes'.
You can do this several ways (a) create a form that is just a button and include that using the module or plugin; (b) Use a link to a the current form (or another one) with some kind of &task=del&id=9999 element in the url.
As well as the standard link to form ChronoForms will support 'special' links in two ways:[list]You cna add xtra variable sin the url and parse them in the Form HTML You can add something like &task=extra * to the url and get ChronoForms to execute code from one of the 'Extra Code' boxes on the Form Code tab. This functionality was set up to support Ajax but will work with a call from a url jus as well [/list]
Bob
* I'm not certain of the exact parameters but can find them if you need them.
Not quite sure where you want to put it but 'yes'.
You can do this several ways (a) create a form that is just a button and include that using the module or plugin; (b) Use a link to a the current form (or another one) with some kind of &task=del&id=9999 element in the url.
As well as the standard link to form ChronoForms will support 'special' links in two ways:[list]
Bob
* I'm not certain of the exact parameters but can find them if you need them.
I was so proud I found a solution to my first issue myself but now I have to say you've lost me. Since it's an old thread I'll try explain in short. I'm trying to build a small reservation form for parties witch will appear in the article with the party details.
What I managed to do with the help of this thread is. Check if the user has already made a reservation.
- If the user did not make a reservation it will show the little form.
- If the user did make a reservation it will not show the form but it will show a message saying he has already made a reservation.
With this message I would like to ad a button so that the user can undo his reservation.
Between the brackets after "else" is the form showing for the users that don't have a reservation yet. (I removed the form code for better overview)
Between the brackets after "if" you see the message the user sees in case he has already made a reservation. This is where I would like to ad the button.
It needs to do the opposite then what the form does. It has do delete the record holding the logged in user's reservation. Since the code can see if this person already made a reservation I assume it's not that far away to have a button to delete his reservation.
What I managed to do with the help of this thread is. Check if the user has already made a reservation.
- If the user did not make a reservation it will show the little form.
- If the user did make a reservation it will not show the form but it will show a message saying he has already made a reservation.
With this message I would like to ad a button so that the user can undo his reservation.
<?php
$user =& JFactory::getUser();
$db =& JFactory::getDBO();
$query = "
SELECT count(*)
FROM `jos_chronoforms_Reservatie`
WHERE `cf_user_id` = ".$db->Quote($user->id).";
";
$db->setQuery($query);
if ( $db->loadResult() ) {
echo "this user has already made a reservation";
// button to delete this users reservation
} else {
echo "show the reservation form";
}
?>
Between the brackets after "else" is the form showing for the users that don't have a reservation yet. (I removed the form code for better overview)
Between the brackets after "if" you see the message the user sees in case he has already made a reservation. This is where I would like to ad the button.
It needs to do the opposite then what the form does. It has do delete the record holding the logged in user's reservation. Since the code can see if this person already made a reservation I assume it's not that far away to have a button to delete his reservation.
Hi mackirony,
In the 'delete' part add a submit button (probably named 'Delete' and a hidden field with the name 'delete' and a value of the record/user id.
In the OnSubmit code check for the hidden field in the $_POST array and if it's there delete the corresponding record. (Actually I'd mark it as unpublished so you have a record.)
Bob
In the 'delete' part add a submit button (probably named 'Delete' and a hidden field with the name 'delete' and a value of the record/user id.
In the OnSubmit code check for the hidden field in the $_POST array and if it's there delete the corresponding record. (Actually I'd mark it as unpublished so you have a record.)
Bob
Thanks Bob,
Especially for thinking I am a coder ;-).
The first part I might be able to do. The second I'm lost.
I usually just try a thousand things and get lucky every once in a while. ;-)
Update: I added the button and the hidden field. The button shows up in case the user has made a reservation so thats ok. When I click it it creates new record witch is logical since I have no clue where to start with the OnSubmit and $_POST part.
I've been searching the web but there are so many ways t use this $_POST thing I don't know where to start. Maybe you can give me another hint? 8)
Especially for thinking I am a coder ;-).
The first part I might be able to do. The second I'm lost.
I usually just try a thousand things and get lucky every once in a while. ;-)
Update: I added the button and the hidden field. The button shows up in case the user has made a reservation so thats ok. When I click it it creates new record witch is logical since I have no clue where to start with the OnSubmit and $_POST part.
I've been searching the web but there are so many ways t use this $_POST thing I don't know where to start. Maybe you can give me another hint? 8)
Hi Mackirony,
The $_POST array is versatile because it is the PHP name for the array of results from a form. Each input in your form will have an equivalent value in the $_POST array* that you can access and use in PHP. The array is a series of 'name' => 'value' pairs where the name is the 'name' of the form input.
If you have two submit buttons in your form then the value of the one that is clicked will be passed back.
Bob
*Actually unchecked check-boxes don't but that's a minor problem.
The $_POST array is versatile because it is the PHP name for the array of results from a form. Each input in your form will have an equivalent value in the $_POST array* that you can access and use in PHP. The array is a series of 'name' => 'value' pairs where the name is the 'name' of the form input.
If you have two submit buttons in your form then the value of the one that is clicked will be passed back.
<input 'type='submit' name='submit' value='Submit' />
<input 'type='submit' name='submit' value='Delete' />
Then in the OnSubmit side you can check the value of the variable and take appropriate action<?php
$submit = JRequest::getString('submit', '', 'post');
if ( $submit == 'Delete' ) {
// delete something
} else {
// do something else
}
?>
Bob
*Actually unchecked check-boxes don't but that's a minor problem.
Thanks Bob,
We have been trying to get this to work (me with a friend who has a better php knowledge)
We have paste this code in "On Submit code - before sending email:"
The function of the other button is still happening. Namely a new (but empty) record will be created in the database. I'm assuming the submit button triggers something in the plugin that does what the plugin does, namely "creating records". It seems, the code above is never run.
any ideas?
this is the form code:
tx
We have been trying to get this to work (me with a friend who has a better php knowledge)
We have paste this code in "On Submit code - before sending email:"
<?php
$submit = JRequest::getString('submit', '', 'post');
if ( $submit == 'delete reservation' ) {
mysql_query("DELETE FROM `jos_chronoforms_Reservatie`
WHERE `cf_user_id` = '{$_POST["remuser"]}');
} else {
// do something else
}
?>
The function of the other button is still happening. Namely a new (but empty) record will be created in the database. I'm assuming the submit button triggers something in the plugin that does what the plugin does, namely "creating records". It seems, the code above is never run.
any ideas?
this is the form code:
<?php
$my = JFactory::getUser();
?>
<?php
$user =& JFactory::getUser();
$db =& JFactory::getDBO();
$query = "
SELECT count(*)
FROM `jos_chronoforms_Reservatie`
WHERE `cf_user_id` = ".$db->Quote($user->id).";
";
$db->setQuery($query);
if ( $db->loadResult() ) {
echo "this user has already responded";
echo "<input value='delete reservation' name='remof' id='remof' type='submit' />";
echo "<input type='input' id='remuser' name='remuser' value='".$my->id ."' />";
}
else {
echo "<input class='cf_inputbox required' maxlength='150' size='30' title='' id='naam' name='naam' type='text' value='".$my->name."' readonly='readonly' />
<select class='cf_inputbox validate-selection' id='select_1' size='1' title='' name='aantal'><option value=''>Choose Option</option><option value='1'>1</option><option value='2'>2</option></select>
<input value='Verzend' name='undefined' type='submit' />";}
?>
tx
This topic is locked and no more replies can be posted.