Hi folks,
I'm working on a project, and I have a quick question. OK, it really isn't that quick. The site is PHP/MySQL, and I've just added a javascript component - my question is related to the PHP side of things:
I want to add a couple of radio buttons and a text field to my name input form. It has a drop-down for title, a text field for firstname, one for MI, one for last name, and a drop-down for degree.
What I want to do is to give my users the option to enter a degree not found on the list. Since my desires happen at the client side, I've worked out in javascript how to use a radio button to select one or the other - the degree dropdown, or the degreealt text box. I've also got the radio buttons set so that the non-selected option is dynamically enabled/disabled. While I haven't worked it into the pages, yet, that code is here:
It's heavily based on something I found at W3schools.com, but I clunked it together, and it does what I need it to, or almost.
I'll use this script to select the drop-down or the text-field - now I need to know how to capture the correct data.
This is the code that retrieves the input and adds the incrementals:
This is the $form data that collects the data for the previous code snippet:
This is the code on recipients_add.php that processes the input from the input page:
Basically, they are limited to a max of 25 names, and the insert shuts itself off if the first name field is blank (this is a required entry, and is validated in a previous step, so a blank value means there is no entry for that line . . . anyhow, it works.
The site uses a template class - this explains why there is some weird code here and there. There are also custom classes for email and mysql functions - the syntax works as shown.
Before anyone asks, I'm anovice coder, just above newbie, and this site was coded by a contractor. I've been asked to (try to) make enhancements after he was unable to commit to further development work. I've read a few books and read LOTS of FAQs, and I pretty much understand what is happening at each step. That said, I know I can use an IF...ELSE statement to determine which field is selected, but I do not know how to subsequently pass the variable of the field associated with the radio button off as the captured value for "degree."
I've tried to provide as much as possible - maybe too much, but I really need the help - we're supposed to go liove on Monday, and I'm hitting the wall.
If anyone can explain the steps I need to take, how I need to nest my if..elses, where I need to insert the js commands (I'm assuming it's odone inline, like the script example at top, anythig at all that would be of use to me, please chime in.
TIA, everyone.
Regards,
Nedstar1
I'm working on a project, and I have a quick question. OK, it really isn't that quick. The site is PHP/MySQL, and I've just added a javascript component - my question is related to the PHP side of things:
I want to add a couple of radio buttons and a text field to my name input form. It has a drop-down for title, a text field for firstname, one for MI, one for last name, and a drop-down for degree.
What I want to do is to give my users the option to enter a degree not found on the list. Since my desires happen at the client side, I've worked out in javascript how to use a radio button to select one or the other - the degree dropdown, or the degreealt text box. I've also got the radio buttons set so that the non-selected option is dynamically enabled/disabled. While I haven't worked it into the pages, yet, that code is here:
Code:
<html>
<head>
<script type="text/javascript">
}
function doitall()
{
var x=document.getElementById("mySelect")
x.disabled=true
document.forms[0].field.focus()
}
function undoitall()
{
var x=document.getElementById("mySelect")
x.disabled=false
}
</script>
</head>
<body>
<form>
<input type="radio" name="browser" onclick="undoitall()" value="Opera">
<select id="mySelect">
<option>MD</option>
<option>MD PhD</option>
<option>RN</option>
<option>RN BSN</option>
</select>
<input type="radio" name="browser" onclick="doitall()" value="Opera">Other:
<input type="text" name="field" size="30">
</form>
</body>
</html>
It's heavily based on something I found at W3schools.com, but I clunked it together, and it does what I need it to, or almost.
I'll use this script to select the drop-down or the text-field - now I need to know how to capture the correct data.
This is the code that retrieves the input and adds the incrementals:
Code:
<?php
$x = 1;
$submit_form = "<form action='recipients_add.php' method='post'>";
while ($x != 26){
$title = $info["Title"]["$x"][""];
$first_name = $info["First"]["Name"]["$x"];
$middle_name = $info["Middle"]["Name"]["$x"];
$last_name = $info["Last"]["Name"]["$x"];
$degree = $info["Degree"]["$x"][""];
if($first_name != ""){
$submit_form .= "
<input type='hidden' name='Title-$x' value='$title'>
<input type='hidden' name='First-Name-$x' value='$first_name'>
<input type='hidden' name='Middle-Name-$x' value='$middle_name'>
<input type='hidden' name='Last-Name-$x' value='$last_name'>
<input type='hidden' name='Degree-$x' value='$degree'>";
}
$x = $x + 1;
}
$x = 1;
$submit_form .= "<input type='submit' value='Submit Names!'></form>";
?>
This is the $form data that collects the data for the previous code snippet:
Code:
<tr>
<td><div align='center'>1</div></td>
<td><div align='center'>
<select name='Title-1' id='Title-1' value='$title_1'>
<option value='Dr.'>Dr.</option>
<option value='Mr.'>Mr.</option>
<option value='Mrs.'>Mrs.</option>
<option value='Ms.'>Ms.</option>
<option value='' selected='selected'>None</option>
</select>
</div></td>
<td><div align='center'>
<input name='First-Name-1' type='text' id='First-Name-1' value='$first_name_1' size='25' />
</div></td>
<td><div align='center'>
<input name='Middle-Name-1' type='text' id='Middle-Name-1' value='$middle_name_1' size='5' maxlength='5' />
</div></td>
<td><div align='center'>
<input name='Last-Name-1' type='text' id='Last-Name-1' value='$last_name_1' size='25' />
//cell and radio button to select drop-down goes here
</div></td>
<td><div align='center'>
<select name='Degree-1' id='Degree-1' value='$degree_1'>
<option value='MD'>MD</option>
<option value='MD, PhD'>MD, PhD</option>
<option value='RN'>RN</option>
<option value='BSN'>BSN</option>
<option value='' selected='selected'>None</option>
</select>
//cell and radio button for "other" field selection go here
//cell and "other" field go here
</div></td>
</tr>
This is the code on recipients_add.php that processes the input from the input page:
Code:
<?php
session_start();
include("include.php");
foreach ($_POST as $name => $value){
// Take away the number at the end
$namen = explode("-", $name);
$name = $namen["0"];
// Then we make it two words
$name = str_replace("-", " ", $name);
// Get the number
$number = $namen["2"];
$numbert = $namen["1"];
if ($number < 26 ){
$info["$name"]["$numbert"]["$number"] .= "$value";
}
}
$x = 1;
$id = $_SESSION["id"];
$oid = $_SESSION["order_id"];
while ($x != 26){
$title = $info["Title"]["$x"][""];
$first_name = $info["First"]["Name"]["$x"];
$middle_name = $info["Middle"]["Name"]["$x"];
$last_name = $info["Last"]["Name"]["$x"];
$degree = $info["Degree"]["$x"][""];
if ($first_name != ""){
$sql_insert = "INSERT INTO tbl_recips (userID, court_title, firstName, middleInit, lastName, degree, orderID)
VALUES
('$id', '$title', '$first_name', '$middle_name', '$last_name', '$degree', '$oid')";
$do_insert = $mysql->query($sql_insert);
}
$x = $x + 1;
}
$sql_update = "UPDATE tbl_users SET order_complete=1 WHERE userID='$id'";
$do_update = $mysql->query($sql_update);
?>
Basically, they are limited to a max of 25 names, and the insert shuts itself off if the first name field is blank (this is a required entry, and is validated in a previous step, so a blank value means there is no entry for that line . . . anyhow, it works.
The site uses a template class - this explains why there is some weird code here and there. There are also custom classes for email and mysql functions - the syntax works as shown.
Before anyone asks, I'm anovice coder, just above newbie, and this site was coded by a contractor. I've been asked to (try to) make enhancements after he was unable to commit to further development work. I've read a few books and read LOTS of FAQs, and I pretty much understand what is happening at each step. That said, I know I can use an IF...ELSE statement to determine which field is selected, but I do not know how to subsequently pass the variable of the field associated with the radio button off as the captured value for "degree."
I've tried to provide as much as possible - maybe too much, but I really need the help - we're supposed to go liove on Monday, and I'm hitting the wall.
If anyone can explain the steps I need to take, how I need to nest my if..elses, where I need to insert the js commands (I'm assuming it's odone inline, like the script example at top, anythig at all that would be of use to me, please chime in.
TIA, everyone.
Regards,
Nedstar1