Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8417251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:59:18+00:00 2026-06-10T01:59:18+00:00

I have a session variable that is set when the user submits a form

  • 0

I have a session variable that is set when the user submits a form with a certain option selected. When the page refreshes I need to test this session variable and if it exists then make some of the form read only. This is my code so far, php:

<?php
require("header.php");

if(isset($_REQUEST['searching'])){ //check if form has been submitted

echo"<h2>Submitted</H2><p>";
    connect('final');//connect to DB

  $fName = $_POST['addFname']; 
  $lName = $_POST['addLname']; 
  $address = $_POST['address']

  $dropdown = $_POST['field']; // yes or no option 

    $fName = htmlspecialchars($fName); 
    $fName = mysql_real_escape_string($fName); 
    $lName = htmlspecialchars($lName); 
    $lName = mysql_real_escape_string($lName);
    $address = htmlspecialchars($line2); // stop HTML characters
    $address = mysql_real_escape_string($line2); //stop SQL injection


if($dropdown== "no"){
  $_SESSION['name'] = "$fName";    
}     
?>

‘field’ is the name of my dropdown with 2 options yes and no.

MY JS for getting the variable:

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script type = "text/javascript">
var session;
function multi(){
    $.ajaxSetup({cache: false})
    $.get('getSession.php', {requested: 'foo'}, function (data) {
        session = data;
});
}
</script>

I use that to get the variable from the session, getSession.php has the following:

    <?php
session_start();
if (isset($_GET['name'])) {
    // return requested value
    print $_SESSION[$_GET['name']];
} else {
    print json_encode($_SESSION);
}
?>

finally I have this function to disable the text fields

    <script language="JavaScript">
<!--
function enable_text2()
{
if (session !=""){
status = "true";
document.add.addFname.readonly=readonly;
document.add.addLname.readonly=readonly;
}
}
//-->
</script>

the rest of my html is just a form, this is all in one document with the php code at the top, and the javascript functions in the head tag.

I call a wrapper function in the body onload tag, which then calls both of those functions, I thought the first function would get the session variable if it existed from the php document and then the second function would test if it was not empty, if it wasn’t then it would make the fields read only.

However when I select no in the drop down and submit the form, the page refreshes and nothing happens, the fields are not read only.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T01:59:19+00:00Added an answer on June 10, 2026 at 1:59 am

    Why You are using javascript for it??

    session_start();
    if (isset($_GET['name'])) {
        $disable=true;
    } else {
        $disable=false;
    }
    
    
    
     <input type="text" name="addFname" <?php if($disable) { ?> readonly="readonly" <?php } ?>
    

    Here i have taken “addFname” .you can disable any element inside that php if condition

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a certain session variable that is actually an array. I want to
We have various related session variables for a complex page that has various things
I am currently in C# and I have set Session variables on each page.
I have a form on my page, and I want to send the user
I use the PHP Session variable to have a user login and edit their
I have 3 pages in my set up here: login.php: The login page that
I have looked at Storing Form Data as a Session Variable , but nobody
I try to access session variables stored on a different page. When I have
I have a web-based system built with user login data based on session variables.
For a Magento shop I'm working on I have to check certain session variables

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.