Jump to content

How can I put a form inside a form?


coolcam26

Recommended Posts

Here is my code so far...

<head>
<script type="text/javascript" src="includes/jquery.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
  //trigger when clicking element
  $(".toggle").click(function () {
		//check visibility
		if ($(this).next().is(":hidden")) {
			$(this).next().slideDown("slow"); //slide it down
		} else {
			$(this).next().hide(); //hide it
		}
	});
});
</script>
</head>
<?php include("header.inc"); ?>
<table border="0" width="100%"><tr><td valign="top" width="800">
<?php
echo "<div id='content'>";
echo "<h2 div id='title'>";
echo "Messages";
echo "</h2>";

if($_SESSION['uid']){

echo "<div align='right'><a href='create_message.php'>Create Message&nbsp&nbsp</a></div>";

echo "<h3 div id='subtitle'>";
echo "Inbox";
echo "</h3>";

//Inbox///////////////////////////////////////////////////////////////
$query = mysql_query("SELECT * FROM messages WHERE to_user='$username' ORDER BY id DESC");
	$numrows = mysql_num_rows($query);
	if ($numrows != 0){
		echo "<form action='delete_message.php' method='POST'>";
		echo "<div id='messages'>
		<div id='leftside'>From...</div>
		<div id='leftside'><input type='submit' name='deleteinbox' value='Delete' class='button'></div>
		<div id='rightside'>Date</div>
		<div id='center'>Subject and Message</div>
		<div style='clear: both;'></div>
		</div>";

		while($row = mysql_fetch_assoc($query)){
			$msg_id = $row['id'];
			$msg_to_user = $row['to_user'];
			$msg_to_id = $row['to_id'];
			$msg_from_user = $row['from_user'];
			$msg_from_id = $row['from_id'];
			$msg_subject = $row['subject'];
			$msg_content = $row['content'];
			$msg_date = $row['date'];
			$msg_from_delete = $row['from_delete'];
			$msg_to_delete = $row['to_delete'];

			if (!$msg_to_delete){
				echo "<div id='messages'>";
				echo "<div id='leftside'>
				<input type='checkbox' name='cb$msg_id' value='$msg_id'>
				<a href='profile.php?id=$msg_from_id' target='_blank'>$msg_from_user</a>
				</div>";
				echo "<div id='rightside'>$msg_date</div>";

				echo "<div id='center'>
				<span class='toggle'><a href='#'>$msg_subject</a></span>
				<div class='hiddenDiv'>
				<br>$msg_content<br><br>
				<span class='toggle'><a href='#'>REPLY</a></span>
				<div class='hiddenDiv'>
				<form action='msgreply.php' method='POST'>
					<input type='hidden' value='$msg_id' name='replyid'>
					<input type='text' name='replysubject' style='width: 300px;' class='text-box' value='RE: $msg_subject'><br>
					<textarea name='replycontent' style='width: 298px;' rows='5'></textarea><br><br>
					<input type='submit' name='replybutton' class='button' value='Reply'>
				</form>
				</div>
				</div>
				</div>";

				echo "<div style='clear: both;'></div>";
				echo "</div>";
				$num += 1;
			}
		}
		if ($num == 0){
			echo "You have no messages in your inbox.";
		}
		echo "</form>";

	}
	else
		echo "You have no messages in your inbox!";			

	}else
		echo "You must be logged in to view your messages!";
?>
</div>
</td><td width="250">

<?php include("sidebar.inc"); ?>

</td>
</table>
  </body>

</html>

<?php include("footer.inc"); ?>

 

Basically I am making a personal messaging system however I can't seem to find a way of putting the reply form "inside" the delete form.  :confused: Is there any simple answer as I am very new to php.

 

The deletion works fine however whenever I submit a reply it takes me to the delete page!

 

Thanks,

Cameron

Link to comment
Share on other sites

What Ignace is suggesting is using different submit buttons for the action to be taken. The problem with this approach is that pressing enter will submit a form and there will be no submit value to check on the receiving page. However, the only time you would even consider that is if you were using the same form fields for different operations. I can't believe you would be using the same form fields for a "reply" and a "delete". So the solution is as requinix suggested and have two separate forms. One form must be closed before you start another.

 

<form name="reply">
// reply form goes here
</form>

<form name="delete">
// delete form goes here
</form>

Link to comment
Share on other sites

As you can probably tell already I am not very good with php and I also get confused will all the elses and ifs!

 

This is the error message that I got:

 

Parse error: syntax error, unexpected T_ELSEIF in /****/********/public_html/deleteorsend.php on line 46

 

The code I used for it was:

 

<?php include("header.inc"); ?>
<table border="0" width="100%"><tr><td valign="top" width="800">
<div id="content">
<?php
//Start Content
if($_SESSION['uid']){

$replybtn = $_POST['replybutton'];
$inboxbtn = $_POST['deleteinbox'];
$outboxbtn = $_POST['deleteoutbox'];

if ($replybtn){
		$subject = $_POST['replysubject'];
		$content = $_POST['replycontent'];
		$replyid = $_POST['replyid'];

		if ($subject && $content){
			$date = date("M d, Y");
			$query = mysql_query("SELECT * FROM messages WHERE content='$content' AND date='$date'");
			$numrows = mysql_num_rows($query);
			if ($numrows == 0){
				$query = mysql_query("SELECT * FROM messages WHERE id='$replyid' AND to_user='$username'");
				$numrows = mysql_num_rows($query);
				if ($numrows == 1){
					$row = mysql_fetch_assoc($query);
					$to_id = $row['from_id'];
					$to_user = $row['from_user'];

					mysql_query("INSERT INTO messages VALUES ('', '$to_user', '$to_id', '$username', '$userid', '$subject', '$content', '$date', '0', '0')");

					echo "Your reply has been sent. <a href='messages.php'>Click here</a> to return to your inbox.";
				}
				else
					echo "No message was sent. An error has occured!!!!";
			}
			else
				echo "You can NOT resend the same messages.";
		}
		else
			echo "You did not supply a subject and/or message.";
	}
	else{
		echo "You must submit a response to a message.";
		}

elseif ($inboxbtn){
		$query = mysql_query("SELECT * FROM messages WHERE to_user='$username'");
		while ($row = mysql_fetch_assoc($query)){
			$msg_id = $row['id'];
			$value = "cb"."$msg_id";
			$checkbox = $_POST[$value];
			if ($checkbox){
				mysql_query("UPDATE messages SET to_delete='1' WHERE id='$msg_id'");
			}
		}
		echo "The selected messages have been deleted! <a href='messages.php'>Click here</a> to return to your inbox.";
	}
	elseif ($outboxbtn){
		$query = mysql_query("SELECT * FROM messages WHERE from_user='$username'");
		while ($row = mysql_fetch_assoc($query)){
			$msg_id = $row['id'];
			$value = "cb"."$msg_id";
			$checkbox = $_POST[$value];
			if ($checkbox){
				mysql_query("UPDATE messages SET from_delete='1' WHERE id='$msg_id'");
			}
		}
		echo "The selected messages have been deleted! <a href='messages.php'>Click here</a> to return to your inbox.";
	}
	else
		echo "You must click the button!";
}
else
echo "You must be logged in to do that!";
//End Content
?>
</div>
</td><td width="250">

<?php include("sidebar.inc"); ?>

</td>
</table>

<?php include("footer.inc"); ?>
</div>
</div>

 

Is that the sort of thing you were suggesting, I'm not really sure!!

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.