powpow Posted November 24, 2010 Share Posted November 24, 2010 Hello I am having problem with $_SERVER['REQUEST_METHOD'] = 'POST'. I am trying to make it when I get to a page the form is disabled until you press the edit button. This is why I implemented the code above. I wanted to refresh the page and change input from disabled to enabled. However, when I get to this page the form is enabled. <?php @include 'accesscontrol.php'; @include 'db.php'; if($_SERVER['REQUEST_METHOD']= 'POST') { echo "1"; $Disabled = ""; } else { echo "2"; $Disabled = "disabled=\"disabled\""; } echo $Disabled; echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" URL ."<html xmlns=\URL>" ."<title> Hello </title>" ."<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />" ."<head>" ."<style type=\"text/css\">" ."h1{" ."border-bottom-style: double;" ."border-bottom-color: black;" ."border-bottom-width: 5px;" ."}" ."#left{" ."BACKGROUND-COLOR: #5CADFF;" ."}" ."#right{" ."BACKGROUND-COLOR: #5CADFF;" ."}" ."p{" ."background-color:#4682B4;" ."}" ."</style>" ."</head>" ."<body style=\"background-color:#B8B8B8\">" ."<table align=\"center\" style=\"background-color:#B8B8B8\" WIDTH=\"100%\" HEIGHT=\"100%\">" ."<tr valign=\"middle\">" ."<td colspan=3 align=\"center\">" ."<form method=\"post\" action=".$_SERVER['PHP_SELF']." \>" ."<table align=\"center\" cellpadding=\"10\" style=\"background-color:#5CADFF\" width=\"550\" height=\"200\">" ."<tr>" ."<th colspan=6 align=\"center\"><h1>Welcome: ".$uid."</h1></th>" ."</tr>" ."<tr>" ."<td width=40% align=right>" ."UAID:<br> <input type=\"text\" size=\"8\" name=\"UAID\" value=".$_POST['UAID']." /></td>" ."<td width=60% align=center valign=\"top\" >" ."Name (Last, First):<br><input type=\"text\" size=\"8\" name=\"last\" value= ".$_POST['last']." />, <input type=\"text\" size=\"8\" name=\"first\" value= ".$_POST['first']." />" ."</tr>" ."<tr>" ."<td colspan=6 align=\"center\"><input type=\"submit\" value=\"Edit\" />" ."</td>" ."</tr>" ."<tr>" ."</tr>" ."<td align=center valign=\"top\" style=\"background-color:#5CADFF\">" ."</td>" ."<td align=center valign=\"top\" style=\"background-color:#5CADFF\">" ."<h2>HRCMS</h2>" ."</td>" ."<td align=center valign=\"top\" style=\"background-color:#5CADFF\">" ."<h2>UMass</h2>" ."</td></tr><tr>" ."<td align=center>" ."<div id=\"left\">" ."<table border=1 style=\"background-color:#5CADFF\">" ."<th>" ."<td>DEPT</td><td>MD</td><td>ORG</td><td>SEC</td><td>BOG</td><td>SW</td>" ."</th>"; $label = array('MMARS','LCM','NM SEC','Classic MMARS','CAPS','PMIS','WRK COMP'); $table = array('MMars','LCM', 'NMSec', 'ClassMars', 'CAPS', 'PMIS', 'WrkComp'); $i= 0; while($i < 7){ echo "<tr>" ."<td>".$label[$i]."</td>"; $sql = "SELECT * FROM ".$table[$i]." WHERE `UAID`= ".$_POST['UAID'].""; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); $m = 1; while(list($ORG,$DEP, $MD, $SEC, $BOG, $SW)=mysql_fetch_row($result)){ $checked = ($ORG==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($DEP==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($MD==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($SEC==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($BOG==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($SW==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.', '.$Disabled.' /></td>'; $m++; } echo "</tr>"; $i ++; } echo "</div>" ."</table>" ."</td>" ."<td align=center valign=\"top\" style=\"background-color:#5CADFF\">" ."<table border=1 style=\"background-color:#5CADFF\">" ."<th>" ."<td>DEPT</td><td>MD</td><td>ORG</td><td>SEC</td><td>BOG</td><td>SW</td>" ."</th>"; $label = array('HR Std','HR Addl','CM Std','CM Addl'); $table = array('HRCMS_HR_Std','HRCMS_HR_Addl', 'HRCMS_CM_Std', 'HRCMS_CM_Addl'); $i= 0; while($i < 4){ echo "<tr>" ."<td>".$label[$i]."</td>"; $sql = "SELECT * FROM ".$table[$i]." WHERE `UAID`= ".$_POST['UAID'].""; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); $m = 42; while(list($ORG,$DEP, $MD, $SEC, $BOG, $SW)=mysql_fetch_row($result)){ $checked = ($ORG==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($DEP==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($MD==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($SEC==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($BOG==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($SW==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.', '.$Disabled.' /></td>'; $m++; } echo "</tr>"; $i ++; } echo "</table>" ."</td>"; echo "<td align=center valign=\"top\" style=\"background-color:#5CADFF\">" ."<div id=\"right\">" ."<table border=1 style=\"background-color:#5CADFF\">" ."<th>" ."<td>DEPT</td><td>MD</td><td>ORG</td><td>SEC</td><td>BOG</td><td>SW</td>" ."</th>"; $label = array('HR Std','HR Addl','CM Std','CM Addl'); $table = array('UMASS_HR_Std','UMASS_HR_Addl', 'UMASS_CM_Std','UMASS_CM_Addl'); $i= 0; while($i < 4){ echo "<tr>" ."<td>".$label[$i]."</td>"; $sql = "SELECT * FROM ".$table[$i]." WHERE `UAID`= ".$_POST['UAID'].""; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); $m = 64; while(list($ORG,$DEP, $MD, $SEC, $BOG, $SW)=mysql_fetch_row($result)){ $checked = ($ORG==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($DEP==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($MD==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($SEC==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($BOG==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($SW==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.', '.$Disabled.' /></td>'; $m++; } echo "</tr>"; $i ++; } echo "</table></td></div>" ."<tr>" ."<td align=center valign=\"top\" style=\"background-color:#5CADFF\">" ."</td>" ."<td align=center valign=\"top\" style=\"background-color:#5CADFF\">" ."<h2>Special Access</h2>" ."</td>" ."<td align=center valign=\"top\" style=\"background-color:#5CADFF\">" ."</td></tr><tr>" ."<td></td>" ."<td align=center valign=\"top\" style=\"background-color:#5CADFF\">" ."<table border=1 style=\"background-color:#5CADFF\">"; $sql = "SELECT * FROM `special` WHERE UAID = ".$_POST['UAID'].""; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); $row = mysql_fetch_array($result); $field =array('UAID', 'CAPS_SW_FULL','EMP_REVIEW', 'HR_DISABILITY_DEP', 'HR_DISABILITY_MD', 'HR_EXEMPT_DEP', 'HR_EXEMPT_ORG', 'HR_EXEMPT_SW', 'NM_INTERCEPT_DEP', 'NM_INTERCEPT_SW', 'NM_INTERCEPT_SW', 'NM_INTERCEPT_SW_FULL', 'NMMARS_SW_FULL', 'PMIS_SW_FULL', 'UMASS_HR_EXEMPT_DEP', 'UMASS_HR_EXEMPT_SW' ); $Disabled = "disabled=\'true\'"; $m=64; $i=1; while($i < 15){ echo "<tr><td>" .$field[$i]."</td>"; $checked = ($row[$i]==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td></tr>'; $m++; $i++; } mysql_free_result($result); echo "</table>" ."</td>" ."<td></td></tr></table></td></div>" ."</td></tr></table></body></html>"; ?> Again, would like to come to the page with the post not set. Having the form disabled and then enabled by clicking the edit button. Thank you powpow Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 24, 2010 Share Posted November 24, 2010 if($_SERVER['REQUEST_METHOD'] == 'POST') Quote Link to comment Share on other sites More sharing options...
tecno40 Posted November 24, 2010 Share Posted November 24, 2010 You need javascript to do this, unless you plan on refreshing the page when they click edit. Quote Link to comment Share on other sites More sharing options...
powpow Posted November 24, 2010 Author Share Posted November 24, 2010 techno I was under the impression that php forms could send data to the same page and refresh it. Is this not what my code is doing? Do you have any examples of this js code? Pikachu2000 Sorry about the PM my post disappeared for a little while and I thought it was closed. Any more suggestions. thank you Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 24, 2010 Share Posted November 24, 2010 When I test this locally, it appears to work as written, with the one change I pointed out above. Look at the html in 'View Source' when you load the page and see if the form field tags are correct or not. Quote Link to comment Share on other sites More sharing options...
powpow Posted November 24, 2010 Author Share Posted November 24, 2010 Look at the html in 'View Source' when you load the page and see if the form field tags are correct or not. I tried to do this but I am running my html through php echo statements and it makes it awful to read. I was wondering since I am posting from a form on the previous site could this site be getting the post =true from the previous one? I was able to get it to work with a hidden field. A simple if statement and once that field has been submitted the code works correctly. However, I would like to make it work with out any hidden fields because of accessibility. Here is the working code: <?php @include 'accesscontrol.php'; @include 'db.php'; //if($_SERVER['REQUEST_METHOD'] == 'POST') if(isset($_POST['trick'])) { echo "1"; $Disabled = ""; } else { echo "2"; $Disabled = "disabled=\"disabled\""; } echo $Disabled; echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" ."<html xmlns=\"http://www.w3.org/1999/xhtml\">" ."<title> Hello </title>" ."<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />" ."<head>" ."<style type=\"text/css\">" ."h1{" ."border-bottom-style: double;" ."border-bottom-color: black;" ."border-bottom-width: 5px;" ."}" ."#left{" ."BACKGROUND-COLOR: #5CADFF;" ."}" ."#right{" ."BACKGROUND-COLOR: #5CADFF;" ."}" ."p{" ."background-color:#4682B4;" ."}" ."</style>" ."</head>" ."<body style=\"background-color:#B8B8B8\">" ."<table align=\"center\" style=\"background-color:#B8B8B8\" WIDTH=\"100%\" HEIGHT=\"100%\">" ."<tr valign=\"middle\">" ."<td colspan=3 align=\"center\">" ."<form method=\"post\" ".$_SERVER['PHP_SELF']." \>" ."<table align=\"center\" cellpadding=\"10\" style=\"background-color:#5CADFF\" width=\"550\" height=\"200\">" ."<tr>" ."<th colspan=6 align=\"center\"><h1>Welcome: ".$uid."</h1></th>" ."</tr>" ."<tr>" ."<td width=40% align=right>" ."UAID:<br> <input type=\"text\" size=\"8\" name=\"UAID\" value=".$_POST['UAID']." /></td>" ."<td width=60% align=center valign=\"top\" >" ."Name (Last, First):<br><input type=\"text\" size=\"8\" name=\"last\" value= ".$_POST['last']." />, <input type=\"text\" size=\"8\" name=\"first\" value= ".$_POST['first']." />" ."</tr>" ."<tr>" ."<td colspan=6 align=\"center\"><input type=\"submit\" value=\"Edit\" />" ."</td>" ."</tr>" ."<tr>" ."</tr>" ."<td align=center valign=\"top\" style=\"background-color:#5CADFF\">" ."</td>" ."<td align=center valign=\"top\" style=\"background-color:#5CADFF\">" ."<h2>HRCMS</h2>" ."</td>" ."<td align=center valign=\"top\" style=\"background-color:#5CADFF\">" ."<h2>UMass</h2>" ."</td></tr><tr>" ."<td align=center>" ."<div id=\"left\">" ."<table border=1 style=\"background-color:#5CADFF\">" ."<th>" ."<td>DEPT</td><td>MD</td><td>ORG</td><td>SEC</td><td>BOG</td><td>SW</td>" ."</th>"; $label = array('MMARS','LCM','NM SEC','Classic MMARS','CAPS','PMIS','WRK COMP'); $table = array('MMars','LCM', 'NMSec', 'ClassMars', 'CAPS', 'PMIS', 'WrkComp'); $i= 0; while($i < 7){ echo "<tr>" ."<td>".$label[$i]."</td>"; $sql = "SELECT * FROM ".$table[$i]." WHERE `UAID`= ".$_POST['UAID'].""; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); $m = 1; while(list($ORG,$DEP, $MD, $SEC, $BOG, $SW)=mysql_fetch_row($result)){ $checked = ($ORG==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($DEP==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($MD==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($SEC==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($BOG==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($SW==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.', '.$Disabled.' /></td>'; $m++; } echo "</tr>"; $i ++; } echo "</div>" ."</table>" ."</td>" ."<td align=center valign=\"top\" style=\"background-color:#5CADFF\">" ."<table border=1 style=\"background-color:#5CADFF\">" ."<th>" ."<td>DEPT</td><td>MD</td><td>ORG</td><td>SEC</td><td>BOG</td><td>SW</td>" ."</th>"; $label = array('HR Std','HR Addl','CM Std','CM Addl'); $table = array('HRCMS_HR_Std','HRCMS_HR_Addl', 'HRCMS_CM_Std', 'HRCMS_CM_Addl'); $i= 0; while($i < 4){ echo "<tr>" ."<td>".$label[$i]."</td>"; $sql = "SELECT * FROM ".$table[$i]." WHERE `UAID`= ".$_POST['UAID'].""; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); $m = 42; while(list($ORG,$DEP, $MD, $SEC, $BOG, $SW)=mysql_fetch_row($result)){ $checked = ($ORG==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($DEP==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($MD==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($SEC==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($BOG==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($SW==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.', '.$Disabled.' /></td>'; $m++; } echo "</tr>"; $i ++; } echo "</table>" ."</td>"; echo "<td align=center valign=\"top\" style=\"background-color:#5CADFF\">" ."<div id=\"right\">" ."<table border=1 style=\"background-color:#5CADFF\">" ."<th>" ."<td>DEPT</td><td>MD</td><td>ORG</td><td>SEC</td><td>BOG</td><td>SW</td>" ."</th>"; $label = array('HR Std','HR Addl','CM Std','CM Addl'); $table = array('UMASS_HR_Std','UMASS_HR_Addl', 'UMASS_CM_Std','UMASS_CM_Addl'); $i= 0; while($i < 4){ echo "<tr>" ."<td>".$label[$i]."</td>"; $sql = "SELECT * FROM ".$table[$i]." WHERE `UAID`= ".$_POST['UAID'].""; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); $m = 64; while(list($ORG,$DEP, $MD, $SEC, $BOG, $SW)=mysql_fetch_row($result)){ $checked = ($ORG==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($DEP==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($MD==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($SEC==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($BOG==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td>'; $m++; $checked = ($SW==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.', '.$Disabled.' /></td>'; $m++; } echo "</tr>"; $i ++; } echo "</table></td></div>" ."<tr>" ."<td align=center valign=\"top\" style=\"background-color:#5CADFF\">" ."</td>" ."<td align=center valign=\"top\" style=\"background-color:#5CADFF\">" ."<h2>Special Access</h2>" ."</td>" ."<td align=center valign=\"top\" style=\"background-color:#5CADFF\">" ."</td></tr><tr>" ."<td></td>" ."<td align=center valign=\"top\" style=\"background-color:#5CADFF\">" ."<table border=1 style=\"background-color:#5CADFF\">"; $sql = "SELECT * FROM `special` WHERE UAID = ".$_POST['UAID'].""; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); $row = mysql_fetch_array($result); $field =array('UAID', 'CAPS_SW_FULL','EMP_REVIEW', 'HR_DISABILITY_DEP', 'HR_DISABILITY_MD', 'HR_EXEMPT_DEP', 'HR_EXEMPT_ORG', 'HR_EXEMPT_SW', 'NM_INTERCEPT_DEP', 'NM_INTERCEPT_SW', 'NM_INTERCEPT_SW', 'NM_INTERCEPT_SW_FULL', 'NMMARS_SW_FULL', 'PMIS_SW_FULL', 'UMASS_HR_EXEMPT_DEP', 'UMASS_HR_EXEMPT_SW' ); $Disabled = "disabled=\'true\'"; $m=64; $i=1; while($i < 15){ echo "<tr><td>" .$field[$i]."</td>"; $checked = ($row[$i]==1) ? 'checked="checked"' : ''; echo '<td><input type="checkbox" name="admin[]" value="'.$m.'" '.$checked.' , '.$Disabled.' /></td></tr>'; $m++; $i++; } mysql_free_result($result); echo "</table>" ."</td>" ."<td></td></tr></table></td></div>" ."</td></tr>" .'<input type="hidden" name="trick">' ."</form></table></body></html>"; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.