6

I want to place a custom html/php form for my registered Joomla users but I want it to be submitted by the user only once, i mean if a user has submitted the form , the next time he'll open that form page, he should not see the form again? Instead, he should see a custom message (like You have already submitted the form or bla bla bla....) How to achieve this?

3

When you say "custom", I hope you mean that you are going to stick to Joomla methods and make this a module or component ;)

Best way you can do this is by using some of the methods you have been already using. And by that I mean getting the user object.

So, when a user submits the form, not only does it submit the data they have inputted, but it also submits their username, using $user->username. Moving forward, we now supposedly have their username stored in the database along with the data they submitted.

You now need to write a database query getting the username from the table and match it against the current logged in user. Here is a small example:

$db = JFactory::getDbo();
$user = JFactory::getUser();

$query = $db->getQuery(true);
$query->select($db->quoteName('username'));
      ->from($db->quoteName('#__myform'));
      ->where($db->quoteName('username') . ' = '. $db->quote($user->username));
$db->setQuery($query);

$result = $db->loadResult();

if($result) {
    // display custom message
}
else {
    // display form
}

I think it would be an idea to get the form working first and then to start integrating the user check.

Hope this helps

  • I am sorry, i couldn't understand your answer properly, i mean the data of the form gets deposited into my mailbox when the submit button is pressed & a thankyou message is displayed to the user. How will there usernames get stored in the database? – saibbyweb May 26 '14 at 17:27
  • You will need to do the coding for that. Its the only reliable method to check whether the user has filled in the form before or not – Lodder May 26 '14 at 17:35
  • I don't know how to code this out! Can you provide me the script which i will paste in the PHP file which gets executed on the submitting the form. The script should store the username in the database, May be after then your above answer will help out – saibbyweb May 26 '14 at 17:44
  • I'm not going to do all your work for you. You should start writing the form module and post the another question when you run into a issue with your current code. You initial question has already been answered twice. Each one being different so it's not up to you to choose which method you want to go along with and start ;) – Lodder May 26 '14 at 19:38
  • joomla.stackexchange.com/questions/1027/… [Inserting data into Joomla database] – saibbyweb May 27 '14 at 9:40
2

I am not sure what extension you are using to generate the form. But if you have the possibility to change it to "Chronoforms" you can do this for this extension as suggested here: http://www.chronoengine.com/forums/posts/t9535/p9535/user-submit-only-once.html

NOTE: Even if you do not use chronoforms, you can still use the underlying method as it uses standard functions and framework of Joomla.

This is exactly what you are looking for, but the catch is you have to use chronoforms, which by the way are the best free form extension for Joomla anyway, in my opinion. The support is excellent, well maintained. I use it for my site too.

0

Use B2J Contact to generate custom fields in a form. It's a free Joomla form creator component provided by Bang2Joom Team. Nice and easy backend! Friendly support!

Just try it!

Download here: http://www.bang2joom.com/joomla-components/b2j-contact

  • And does this extension have what the OP requires? Explain your answer in more detail please – Lodder May 27 '14 at 1:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.