I got this form :
{{ form_start(form) }}
<input type="submit" class="form_submit_button" name="register_interest" value="Add to favourites"/>
{{ form_end(form) }}
I want to check if user is logged in and I did this :
{% if is_granted('IS_AUTHENTICATED_FULLY') %}
And it hides the button if the user is not logged in.
I want that button to show even if I am not logged in and after the form submit to check if the user is logged in .
How can I do this?
Thank you!
The check must be performed in your php controller. Additionally, you can also perform a javascript check which prevents submitting the form if user is not logged in.
To check for user login in your controller:
if ($this->isGranted('ROLE_USER') == false) {
// show some error message, throw exception etc...
}
Another way to do this:
$this->denyAccessUnlessGranted('ROLE_USER');
To check on the client side (javascript), you could do something like this:
{% if not is_granted('IS_AUTHENTICATED_REMEMBERED') %}
<script>
// wrap into document.ready() if needed
$('#your_submit_button_id').on('click', function(e) {
e.preventDefault();
alert('You must be logged in to use this function');
});
</script>
{% endif %}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments