Buy Now
Sign in

User Submit only once?

gjr , June 13 2008, 16:56
G
gjr 4
June 13 2008, 16:56 #9535
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?
GreyHead 64
June 14 2008, 05:02 #9547
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
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
G
gjr 4
June 14 2008, 11:39 #9557
Thanks Bob - Not much of a coder - any chance you could post some code hints?
G
gjr 4
June 16 2008, 19:53 #9595
Most likely not the best solution, but it is working for me. In the form code block I put:


<?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...;)
GreyHead 64
June 16 2008, 20:00 #9596
Hi gjr,

That looks good to me :-)

Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
S
smappler 14
March 23 2009, 16:44 #27465
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!)
GreyHead 64
March 23 2009, 17:16 #27469
Hi smappler,

Are they logged in users or guests?

Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
S
smappler 14
March 23 2009, 17:27 #27474
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.
GreyHead 64
March 23 2009, 18:37 #27480
Hi smappler,

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 debugging

Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
S
smappler 14
March 23 2009, 23:57 #27502
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.
admin 27
March 24 2009, 04:15 #27516
leave the else empty, add this to redirect:

$mainframe->redirect('index.php', 'you are already signed up!');
Max
If your main question got answered then please mark the answer using the button!
Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
M
mackirony 47
September 23 2009, 09:40 #40739
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:

<?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">&nbsp;</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">&nbsp;</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
M
mackirony 47
September 23 2009, 12:03 #40740
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):
<?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.
GreyHead 64
September 23 2009, 12:27 #40741
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
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
M
mackirony 47
September 23 2009, 12:54 #40743
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?
GreyHead 64
September 23 2009, 13:33 #40747
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:
    [*]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[/*]

Bob

* I'm not certain of the exact parameters but can find them if you need them.
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
M
mackirony 47
September 23 2009, 14:25 #40753
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.


<?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.
GreyHead 64
September 23 2009, 14:41 #40757
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
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
M
mackirony 47
September 23 2009, 15:00 #40760
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)
GreyHead 64
October 04 2009, 16:04 #41245
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.
<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.
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much