Article 6FVWA PHP Button Lable Toggle

PHP Button Lable Toggle

by
TBotNik
from LinuxQuestions.org on (#6FVWA)
All,

I have the following simple code:
Code:<?php
/**************************************************************************/
/* Author: Nyle E. Davis Create Date: 23/10/06 */
/* Modifier: Nyle E. Davis Modify Date: */
/* Run CMD: php /3T/Scripts/Projects/accoungts.php */
/* Purpose: This proc allows additions to the 4-2-Day DB, by the Admin */
/* but only displays to the non-Admin users. All Users must */
/* register to get the daily texts and devotional scriptures */
/* and thoughts recorded in the DB. the DBs used are both */
/* the 42dy DB, the Pursuit of Holiness devotional and the */
/* My Utmost for His Highest devotional. Under certain */
/* conditions the 2 devotional DBs may be combined. */
/**************************************************************************/
$DB1 = "42Day"; // Declare the 4 Today DB
$DB2 = "POH"; // Declare the POH DB
$DB3 = "MyUTHigh"; // Declare the My Utmost DB
$DOY = get_doy (); // Get the Julian Date for today
$usr = ""; // Declare the User ID
$ust = ""; // Declare the User Type/Status
$emo = get_emobj(); // Load the EM framework
$upm = get_usr_perms ($ust); // Get the User permissions
$dsp = get_dsp ($usr,$ust); // Declare the display var
//echo "DOY => $DOY ";

Function get_doy () {
/******************************************************************/
/* Purpose: Get and return the DOY: Day Of the Year. */
/******************************************************************/
return date('z');
} // end function get_doy

Function get_emobj () {
/******************************************************************/
/* Purpose: Get and load the EM framework objects. */
/******************************************************************/

} // end function get_emobj

Function get_usr_perms () {
/******************************************************************/
/* Purpose: Pull the user permissions from the DB. */
/******************************************************************/

} // end function get_usr_perms

Function get_dsp ($usr, $ust) {
/******************************************************************/
/* Purpose: Get the display screen values to display in HTML. */
/* Parms: $usr: the USERID & $ust: USER status/permissions. */
/******************************************************************/
$dsp1 = get_hdr ();
$dsp2 = $dsp1.get_tbl ($usr, $ust);
return $dsp2;
} // end function get_dsp

Function get_hdr () {
/******************************************************************/
/* Purpose: Get the display screen values to display in HTML. */
/* Parms: $usr: the USERID & $ust: USER status/permissions. */
/******************************************************************/
$hdr = "<center><h2>Accounts/Contacts Page</h2>
<h4>Search, Add, Manage Accounts/Contacts</h4>
</center>";
return $hdr;
} // end function get_hdr

Function get_tbl ($u,$t) {
/******************************************************************/
/* Purpose: Get the display screen values to display in HTML. */
/* Parms: $usr: the USERID & $ust: USER status/permissions. */
/******************************************************************/
if ( (empty($u)) || (empty($t))) {
$ls = 'checked';
$ss = 'unchecked';
if (isset($_POST['mode'])) {
$selected_radio = $_POST['mode'];
if ($selected_radio == 'login') {
$ls = 'checked';
$bn = 'Login';
} else if ($selected_radio == 'signup') {
$ss = 'checked';
$bn = 'Sign Up';
} // end if else
} else {
$ls = 'checked';
$bn = 'Login';
} // end if isset
echo $bn;
$tbl = "<center><h3>Login or Sign Up!</h3></center>
<table width='25%' align='center' border='0'>
<tr>
<td><INPUT TYPE='RADIO' Name ='type'
value= 'login' action=
get_lab()>Login</td>
<td><INPUT TYPE='RADIO' Name ='type'
value= 'signup' action=
get_lab()>Sign Up</td>
</tr>
</table>
<table width='45%' align='center' border='0'>
<tr>
<td>Enter User ID! ==></td>
<td><INPUT TYPE='Text' size='20'></td>

</tr>
<tr>
<td>Enter Password! ==></td>
<td><INPUT TYPE='Text' size='20'></td>
</tr>
</table>
<center><INPUT TYPE='submit' value=$bn></center>";

} else {
$m = "<center><h3>Mode</h3></center>";
$tbl = $m."<center><h2>Accounts/Contacts Page</h2>
<h4>Search, Add, Manage Accounts/Contacts</h4>
<h3>Mode</h3>
</center>
<table width='35%' align='center' border='0'>
<tr>
<td><INPUT TYPE='RADIO' Checked> Search</td>
<td><INPUT TYPE='RADIO'>Add</td>
<td><INPUT TYPE='RADIO'>Manage</td>
</tr>
</table>
<table width='65%' align='center' border='0'>
<tr>
<td>Enter search term! ==></td>
<td><INPUT TYPE='Text' size='35'></td>
<td><INPUT TYPE='submit' value='Search'></td>
</tr>
</table>";
} // end if empty
return $tbl;
} // end function get_hdr

Function prc_rad () {
/******************************************************************/
/* Purpose: Get the display screen values to display in HTML. */
/* Parms: $usr: the USERID & $ust: USER status/permissions. */
/******************************************************************/
$rval = $_POST["type"];
if($rval == "login") {
$ls = 'checked';
$bn = 'Login';
} else if ($rval == 'signup') {
$ss = 'checked';
$bn = 'Sign Up';
} // end $rval
} // end function prc_rad

?>

<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
<?php echo $dsp; ?>

</form>
</body>
</html>You'll see in the get_tbl function I correctly toggle the selected 'RADIO' buttons, but the $bn (Button Name) does not change and must for the processing function is looking for the Name of the SUBMIT button where:
  1. Sign Up: Will add the user to the User table in the DB,
  2. Login: Will query the user table for the registered user,
Somehow I'm not getting this done, which cqn still be done in the PHP codeing section, which I've done before but forgnotten how. I think the "toggle action" has to chnge to call a function, but did this probably 15-20 years back, so need help. None on the published HOWTOs gve me the right answer, and I tried 5. The only one that worked used javascript which I do not want to use.

All help appreciated.

Cheers!

TBNK
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments