0

Hey guys, I have been looking for hours, and I can't find the correct solution or know where to even start...

I got this script, and when I click on a radiobutton from the part of the website, it needs to change the reasons (other radiobuttons). Can anyone help me to get started?
And if you got any suggestions regarding to make this code more optimized, please let me know, I'm not that good in php...

In the case below the reasons are made for the chat option... So I need to know how to let it change on change of website part change

Thanks! Code is below

<?

session_start();

if(!session_is_registered(moderator)){

header("location:main_login.php");

}

?>

<form action="reportsubmit.php" method="post">

<p>User: <br /><input type="text" name="user" tabindex="2"/>
</p>
<p>Section of website<br /><input type="radio" name="section" value="profile" />Profile

  <input type="radio" name="section" value="chat" />Chat
  <input type="radio" name="section" value="forums" />Forums
</p>
<p>Reason: <br /> <input type="radio" name="reason" value="predator" />Predator
  <br />
  <input type="radio" name="reason" value="floodspam" />Flooding / Spam<br />
  <input type="radio" name="reason" value="porn" />Posting pornographic content<br />
  <input type="radio" name="reason" value="personal" />Posting personal information<br />
  <br />
  Additional information: <br />
  <textarea name="additionalinfo" cols="30" rows="5" id="additionalinfo" tabindex="3"></textarea>
  <br />
  <br />
  No IP Address has to be provided, this IP Address is recorded automaticaly.<br />
  <br />
  Action: <br /><input type="radio" name="action" value="freeze">Freeze</input><input type="radio" name="action" value="kick">
  KICK</input>
  <br />
  <br />
<input type="Submit" name="Submit" value="Submit"/></p>
</form>
<?

	if (isset($_POST['Submit'])) { 
	if (isset($_SESSION['emoderator'])){

$psswd = $_POST['pass'];
$epass = md5($_POST['pass']);
$euser = $_POST['user'];
$eipaddress = $_POST['ipaddress'];
$ereason = $_POST['reason'];
$ecomment = $_POST['additionalinfo'];
$esection = $_POST['section'];
$eaction = $_POST['action'];

include 'db.php';
	 
						 
	

//Start UserID lookup
// Look up UserID & if this user can be reported (moderators can't be reported for now)
// Or if the user has been banned already, it will not work either.


$getuserid = "SELECT username,gid,block FROM jos_users WHERE username = '".addslashes($euser)."'";
$getuseridresult = mysql_query($getuserid);
$rowuser = @mysql_fetch_array ($getuseridresult);
	$username = $rowuser['0'];
	$usergid = $rowuser['1'];
	$userblock = $rowuser['2'];


					if ($usergid >= 19) {
echo "
   <script type='text/javascript'>
       alert(\"You can't report fellow moderators or higher staff!\");
   </script>
";
					die();
					} 


	


//Start Reporting
			$emod= $_SESSION['emoderator'];
$querykick = "INSERT INTO modsite_reports (websitepart, moderator, user, reason, additionalinfo, action, ipaddress) VALUES('$esection','$emod','$username','$ereason','$ecomment','$eaction','$eipaddress')";

if (!mysql_query($querykick))
  {
  die('Error: ' . mysql_error());
  }

echo "
   <script type='text/javascript'>
       alert(\"Report added!\");
   </script>
		";

mysql_free_result();
mysql_close();
 
	}
	}
//End Reporting
	
?>


</body>
</html>

Edited by ShArKss: n/a

3
Contributors
5
Replies
8
Views
7 Years
Discussion Span
Last Post by ShArKss
0

What you're wanting to do requires javascript, such as the onclick or onselect event handlers which would then trigger a function to manipulate your other form fields. PHP is not capable of doing this.

0

Thanks for the reply creed. Do you happen to have a short snippet or a tutorial for me so that I can get started? :) would be very useful. thanks again!

0

Okay here's an example I have used. It's a bit involved.

Your Choice? Yes <input type="radio" value="Y" name="choice" onclick="document.forms[0].reqd[1].checked=true;document.forms[0].duedate.value=''">  No <input type="radio" value="N" name="choice">

Required? Yes <input type="radio" value="Y" name="reqd" onclick="datefunction()">  No <input type="radio" value="N" name="reqd" onclick="document.forms[0].duedate.value=''">

Due date: <input type="text" size="14" maxlength="10" name="duedate" value="">

The first radio has 2 javascript functions "built-in", when YES is selected it selects YES of the 2nd radio , and then clears the value of the Due Date input field.

Selecting YES on the 2nd radio ('Required') calls a date function (not shown here) that sets the value of the Due Date field. Selecting NO clears the value of the Due Date input field.

Hopefully you can follow this :)

Edited by nav33n: Fixed [code] tags.

2

investigate the html <label> tag, will make your input forms more user friendly, by providing the stardard clickable-text that activates the radio button

<script type='text/javascript'>
function show(sec) {
document.getElementById('sec0').style.display='none';
document.getElementById('sec1').style.display='none';
document.getElementById('sec2').style.display='none';
document.getElementById('sec3').style.display='none';
document.getElementById(sec).style.display='block';
} </script>
Section:<br>
|<input type='radio' name='section' id='section1' value='section1' onclick="show('sec1');"><label for='section1'> Section 1</label>|
|<input type='radio' name='section' id='section2' value='section2' onclick="show('sec2');"><label for='section2'> Section 2</label>|
|<input type='radio' name='section' id='section3' value='section3' onclick="show('sec3');"><label for='section3'> Section 3</label>|
<div id='sec0'>| Reason |</div>
<div id='sec1' style='display:none;'>
|<input type='radio' name='reason' value='reason1' id='reason1'>
<label for='reason1'>reason 1</label>|
|<input type='radio' name='reason' value='reason2' id='reason2'>
<label for='reason2'>reason 2</label>|
|<input type='radio' name='reason' value='reason3' id='reason3'><label for='reason3'> reason 3</label>|
</div>
<div id='sec2' style='display:none;'>
|<input type='radio' name='reason' value='reason4' id='reason4'><label for='reason4'>reason 4</label>|
|<input type='radio' name='reason' value='reason5' id='reason5'><label for='reason5'>reason 5</label>|
</div>
<div id='sec3' style='display:none;'>
|<input type='radio' name='reason' value='reason6' id='reason6'><label for='reason6'>reason 6</label>|
|<input type='radio' name='reason' value='reason7' id='reason7'><label for='reason7'>reason 7</label>|
|<input type='radio' name='reason' value='reason999' id='reason999'><label for='reason999'>reason 999</label>|
</div>

all the radio buttons can have the same name, as only groups of them are shown
the IDs give the <label> tag something to anchor to

Edited by almostbob: n/a

Votes + Comments
Solved the problem! Love this guy!
0

investigate the html <label> tag, will make your input forms more user friendly, by providing the stardard clickable-text that activates the radio button

<script type='text/javascript'>
function show(sec) {
document.getElementById('sec0').style.display='none';
document.getElementById('sec1').style.display='none';
document.getElementById('sec2').style.display='none';
document.getElementById('sec3').style.display='none';
document.getElementById(sec).style.display='block';
} </script>
Section:<br>
|<input type='radio' name='section' id='section1' value='section1' onclick="show('sec1');"><label for='section1'> Section 1</label>|
|<input type='radio' name='section' id='section2' value='section2' onclick="show('sec2');"><label for='section2'> Section 2</label>|
|<input type='radio' name='section' id='section3' value='section3' onclick="show('sec3');"><label for='section3'> Section 3</label>|
<div id='sec0'>| Reason |</div>
<div id='sec1' style='display:none;'>
|<input type='radio' name='reason' value='reason1' id='reason1'>
<label for='reason1'>reason 1</label>|
|<input type='radio' name='reason' value='reason2' id='reason2'>
<label for='reason2'>reason 2</label>|
|<input type='radio' name='reason' value='reason3' id='reason3'><label for='reason3'> reason 3</label>|
</div>
<div id='sec2' style='display:none;'>
|<input type='radio' name='reason' value='reason4' id='reason4'><label for='reason4'>reason 4</label>|
|<input type='radio' name='reason' value='reason5' id='reason5'><label for='reason5'>reason 5</label>|
</div>
<div id='sec3' style='display:none;'>
|<input type='radio' name='reason' value='reason6' id='reason6'><label for='reason6'>reason 6</label>|
|<input type='radio' name='reason' value='reason7' id='reason7'><label for='reason7'>reason 7</label>|
|<input type='radio' name='reason' value='reason999' id='reason999'><label for='reason999'>reason 999</label>|
</div>

all the radio buttons can have the same name, as only groups of them are shown
the IDs give the <label> tag something to anchor to

THANK YOU ! I love you!!! :D

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.