Don't you hate when something works...sometimes? I mean, I'd rather if it didn't work at all, at least then I know that something really is wrong. This (IMO) is one of the worst bugs to iron out.
The problem is as follows: I have a page which has iframes in it. One of the iframes is a shoutbox, and directly under that iframe (but not in the iframe) is a textarea for entering a new shout. The PHP code for processing the shout (inserting into mysql) resides inside that iframe. As soon as the user hits the submit button, I need to clear the textarea and refresh the iframe. However, my code is acting up, it's refreshing the whole page, and sometimes it doesn't bother to submit antyhing (but it still refreshes the page
Okay, on the main page, here's the shoutbox form and iframe:
Code: Select all
<form action="shoutbox.php?{$id}" method="post" target="shoutbox" name="shoutbox"><input size="1" name="processshout" type="hidden" value="yes" >
<table width="354" height="319" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="30" background="images/profile_11.gif"> </td>
</tr>
<tr>
<td height="289" valign="top" background="images/profile_12.gif"><table width="212" height="182" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="8"><img src="images/trans.gif" width="384" height="8"></td>
</tr>
<tr>
<td height="120" align="center" valign="middle"><iframe frameborder="0" name="shoutbox" src="shoutbox.php?{$id}"
width="95%" height="165"> </iframe></td>
</tr>
</table>
<table width="284" height="23" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="15" rowspan="3"> </td>
<td width="269">
</td>
</tr>
<tr>
<td height="5" align="left" valign="middle"><img src="images/trans.gif" width="10" height="5"></td>
</tr>
<tr>
<td align="left" valign="middle"> <script language=javascript type=text/javascript>
drawEmoticons (eList);
</script></td>
</tr>
</table>
<table width="380" height="77" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="11"> </td>
<td width="260" align="center" valign="top"><textarea name="shout" cols="29" rows="3" id="shout" onfocus="clearDefaultText(this)">Type your shout in this box</textarea></td>
<td width="109" valign="top"><table width="104" height="70" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="18" height="70"><img src="images/trans.gif" width="6" height="70"></td>
<td width="86" align="left" valign="bottom"><a href = "profile.php?{$id}" onClick='document.shoutbox.submit(); document.shoutbox.shout.value=""'><img src="images/shout_box.gif" border="0" width="82" height="17"></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
</form>Code: Select all
session_start();
include_once("functions.php");
include_once("user_class.php");
require("../smarty/Smarty.class.php");
//id will have to be passed (get)
$id=$_GET['id'];
$user_profile = new User($id);
$info['id']=$id;
//put in new shouts
if ($_POST['processshout']=="yes"){
//if a user is logged, he "shouts" as himself
if (isset($_SESSION['id'])){
if ($_POST['shout']!= "" && $_POST['shout']!="Please type your shout here"){
$current_user = unserialize($_SESSION['user']);
$curr_user_stats = get_object_vars($current_user);
$user_profile->sb_add_shout($id, $curr_user_stats['username'], $_POST['shout']);
header("Location:shoutbox.php?id={$id}\n
Window-target: _top");
}
//dumb user wants to submit a blank message
else {
header("Location: error.php?error=2\n
Window-target: _self");
}
}
//if a user is not logged in, annonymous is disabled, he gets redirected to an error page
else{
header("Location: error.php?error=1\n
Window-target: _top");
}
}