Absar A. Khan Absar A. Khan - 1 year ago 47
HTML Question

Disable input fields if a variable is not set

I have a webpage which allows user to upload an image ONLY IF he is logged in , I'm using session_start() to get my variable $_SESSION['username']. How can I set my text image field such that its only enabled/visible when there is a set value for $_SESSION['username'].

My code below:

<form action="uploadtofile.php" method="post" enctype="multipart/form- data">
<input id="bc0" type="file" name="fileToUpload" id="fileToUpload" >
<input id="bc1" type="submit" value="Upload Image" name="submit" >


Answer Source

Using the code below, the form will only display if the user is logged in.

if(isset($_SESSION['username'])) {
<form action="uploadtofile.php" method="post" enctype="multipart/form-data">
<input id="bc0" type="file" name="fileToUpload" id="fileToUpload">
<input id="bc1" type="submit" value="Upload Image" name="submit">