I would like to validate a form so that it checks if the user is logged in…
I have got a form with method and action given below:
<form method=get action="index.php">
What I would like to do is that when I click on proceed to checkout, this form should validate if user is logged in. If not it will redirect to login page. I am hoping to put my php code inn the form so that user do not proceed to checkout unless he is logged in.
I tried to use onclick”if (($_SESSION[‘user_name’]) == “”)” then it should redirect to login.php.
You’re doing it wrong. PHP code is used on the server side, you can’t use it on the client side
onclick=""attribute.You need to submit the form, and then on the page which handles the request, check if the user is logged in, and if not redirect.