1

Use case: a site that accepts applications for courses. Users need to register first before they can create an application (for security, spam etc.) - however the registration process might put them off; can anyone suggest a way to preview the form?

Requests to '/node/add/application' obviously get Access Denied when not logged in, because Anonymous Users don't have the "Application: Create new content" permission.

1
  • You could alter the form and remove the submit button based on whatever condition you want
    – Ziftman
    May 23, 2018 at 10:29

1 Answer 1

0

can anyone suggest a way to preview the form?

The no code way would be to use screen shots (images).

Alternatively, you could check if the user is logged, it they are not then unset the submit button via a hook_form_alter.

prevent someone from circumventing it by submitting the form manually

Better yet, if user is anonymous, you alter the callback function of the submit button by unsetting the existing one and adding a new custom callback.

3
  • @NoSsweat - thanks - yep, I'd prefer the low maintenance approach (i.e. not regenerating screenshots each time). What about CSRF tokens - i.e. to prevent someone from circumventing it by submitting the form manually - can I remove those from $form too? (apologies I don't have an IDE available here to check) May 23, 2018 at 10:35
  • I can see them here, so yes.
    – No Sssweat
    May 23, 2018 at 12:59
  • Or you could leave the submit button and alter the callback. Perhaps the altered callback shows a drupal_set_message saying form was not submitted, please register to be able to submit or something along those lines.
    – No Sssweat
    May 23, 2018 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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