Jump to content

Mark hidden fields after user has selected 1st field


stockton

Recommended Posts

I have the following code which works fine as far as it goes but I would like a method, preferably using jquery, to mark two fields  hidden or displayed depending on user selection.

<?php
ini_set('display_errors','On');
$POST_MAX_SIZE = ini_get('post_max_size');
$maxlifetime = ini_get('session.gc_maxlifetime');
require_once '../Includes/HeaderFunctions.inc';
    $RecordType = $_POST["RecordType"];
    $TopicName = $_POST["TopicName"];
    $Parent = $_POST["Parent"];
    $helpfile = $_POST["helpfile"];
    $Datum = date("Y-m-d");
    $Tyd = date("H:i:s");
    $MaxFileSize = 350000;
    $Message = "";

    if ($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST) && $_SERVER['CONTENT_LENGTH'] > 0) {
        $Message = sprintf('The server was unable to handle that much POST data (%s bytes) due to its current configuration', $_SERVER['CONTENT_LENGTH']);
        RaiseError(__FILE__, __LINE__, 3, "", $_SERVER['REQUEST_URI'], $Message);
    }

    if (!empty($_REQUEST['submit']))
        $Button = ($_REQUEST['submit']);
        else
        $Button = '';

    if ($Button == 'Submit')      // Submit button pressed.
        {
        if ($RecordType == 0)
            {           
            $SQL = 'INSERT INTO "Primary"."Help" ("TopicName","TopicBody","Parent","DateCreated","TimeCreated","Counter")';
            $SQL .= "VALUES('".$TopicName."',0,0,now(),now(),0);";
            }
            else
            {
            // Found at http://www.webcheatsheet.com/PHP/file_upload.php
            //Сheck that we have a file
            if ((!empty($_FILES["helpfile"])) && ($_FILES['helpfile']['error'] == 0)) 
                {
                $filename = basename($_FILES['helpfile']['name']);
                $filesize = $_FILES["helpfile"]["size"];
                if (($_FILES["helpfile"]["size"]) > 0 && ($_FILES["helpfile"]["size"] < $MaxFileSize))
                    {
                    //Determine the path to which we want to save this file
                    $newname = dirname(__FILE__).'/uploads/'.$filename;
                    //Check if the file with the same name already exists on the server
                    if (!file_exists($newname)) 
                        {
                        //Attempt to move the uploaded file to it's new place
                        if ((move_uploaded_file($_FILES['helpfile']['tmp_name'],$newname))) 
                            {
                            $Message = "It's done! The file has been saved as: ".$newname;
                            } else {
                            $Message = "Error: A problem occurred during file upload!";
                            }
                        } else {
                        $Message = "Error: File ".$newname." already exists";
                        }       
                    } else {
                    $Message = "Error: Invalid file size ".$filesize." bytes which is greater than ".$POST_MAX_SIZE."in ".$maxlifetime; 
                    }
                }
            if ($Message == "") {
                    $fr = fopen($newname, 'r');
                    $Face = fread($fr, filesize($newname));
                    $FaceString = htmlentities($Face,ENT_QUOTES);
                    fclose($fr);
              unlink($newname);
              $SQL = 'INSERT INTO "Primary"."Help" ("TopicName","TopicBody","Parent","DateCreated","TimeCreated","Counter")';
              $SQL .= "VALUES('".$TopicName."',";
              $SQL .= "'".$FaceString."','".$Parent."',";
              $SQL .= "'now()','now()','0');";
//          $Message = $SQL;
          
              $qw =& $DBConnection->query($SQL);

              if (DB::isError($qw))
                  RaiseError(__FILE__, __LINE__, 3, $qw->getMessage(), $_SERVER['REQUEST_URI'], $SQL);
            }
        }   
    }   
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Add help</title>
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="Mon, 22 Jul 2000 11:12:01 GMT"
<!-- Put IE into quirks mode -->
<title><?php echo HOSTDESCRIPTOR ?>: HelpPage</title>
<link rel="stylesheet" type="text/css" href="CSS/Help.css" />
<link rel="stylesheet" href="/CSS/custom-theme/jquery-ui-1.7.1.custom.css"/>
<link rel="stylesheet" href="/CSS/SiteWide.css"/>

<script type="text/javascript" src="/JavaScripts/DWjQuery.js"></script>
<script type="text/javascript" src="/JavaScripts/CL/ComponentLoader.js"></script>
<script type="text/javascript">
$(document).ready( function()
    {
    //load the standard headers.
    $("#header").LoadComponent("<? echo STANDARD_HEADER;?>");
    });
    </script>
</head>
<body bgcolor="#eeeeee">
<div id="container">
<center>
<h2>Help Administration</h2><br>
<?php
   if (($_SESSION['UserRights']) < 0)
      {
      $Message = sprintf("%s %d <br> Your authority does not extend to this facility ", __FILE__, __LINE__);
      trigger_error($Message, E_USER_ERROR);
      exit;
      }
?>
<form name="HelpAdd" action="HelpAdd.php" method="post" enctype="multipart/form-data"> 
<table align="center" border="3" cellspacing="0" cellpadding="3">
<tr><td>Record Type:</td>';
<td><select name="RecordType">
<option value='0'>Parent</option>
<option value='1'>Dependant</option><br/>
<tr><td>Topic Title:</td>
<td><input type="text" name="TopicName" ID="TopicName" maxlength="25"></td></tr>
<tr><td>Parent:</td>
<td><select name="Parent">
<?php
    $SQL = 'Select "TopicID", "TopicName" from "Primary"."Help" WHERE "Parent"=0 ORDER BY "TopicID"'; 
    $qw =& $DBConnection->query($SQL);

    if (DB::isError($qw))
            RaiseError(__FILE__, __LINE__, 3, $qw->getMessage(), $_SERVER['REQUEST_URI'], $SQL);
    $RowCounter = $qw->numRows();
    if($RowCounter==0)
        {
        echo "No records found";
        }
    else
        {
        while($Row = $qw->fetchRow(DB_FETCHMODE_ASSOC))
            {
            $ParentID = $Row['TopicID'];
            $ParentName = $Row['TopicName'];
            echo "<option value=$ParentID>$ParentName</option>";
            }
        }
?>
</td></tr>
<tr><td>Topic Body:</td>
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $MaxFileSize ?>" />
<td><input name="helpfile" type="file" /></td></tr>

<tr><td colspan="2" align="center">
<input type="submit" name="submit" value="Submit">
<a href="/help.php"><button>Back</a>
</td></tr>
<tr><td colspan="2" align="center">
<?php echo $Message ?>
</td></tr>
</table>
</form>
</center>
</div>
        <div id="header">
                loading...
        </div>

</body>
</html>

 

If the user selects RecordType to be a Parent only the TopicTitle needs completion but if the user selects RecordType Dependant then all fields need to be completed or filled in.

So to cut a long story shorter on selection of RecordType two fields are to either appear or disappear.

Maybe I should start with Parent and Topic Body fields hidden and only if user selects Dependant make them visibly.

Suggestions please.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.