I am creating a resources page, on which a resource can be downloaded after filling or submitting a form. This form is having user info fields like first name, last name, email etc. Could anyone please suggest me how can I implement it in Craft.

  • Hi Bhashakar, welcome to Craft Stack Exchange! This question is very broad, can you please edit to make it more specific? It would help to know where you are starting from... what have you already tried?
    – Lindsey D
    Oct 4 '14 at 2:34

It depends to some extent whether the form is a login/registration form (to a user account) or just an information form, that you are saving in the database.

If the resources page is restricted and requires login, then you should place {% requireLogin %} at the top of your resources template. If anyone requests this page they will automatically be redirected to the login page, and after a successful login, will be routed back to the original request, which was the resources page. The login page can have a link to 'create account' with the additional fields you need, if they don't already have one.

If it is just an information form and not for login then you can simply create a form with the required fields. Submit the form using action/saveEntry along with a hidden field called redirect as explained here.

<form method="post" action="" accept-charset="UTF-8">
    <input type="hidden" name="action" value="entries/saveEntry">
    <input type="hidden" name="redirect" value="path/to/resources">

This is not secure however. If you need to make certain that they just don't go straight to the resources page without filling out the form, then you can test for the existence of an entry.id on the resources page (which is what is returned from a successful entries/saveEntry), and redirect them back to the form again if not defined. However, this would make the resources page viewable only once (unless you set a cookie or store session data, etc). And they would have to fill out the form every time they wanted to view it, which doesn't sound like what you want. In which case go with the login route above.

There are example templates for login, user registration, and others (more links at bottom left of those pages).

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.