[英]Messaging issues!
I have a functioning messaging script. 我有一个正常运行的消息传递脚本。 What I am trying to do is allow 2 extra things.
我正在尝试做的是允许2件额外的事情。
One is a message me button. 一个是给我发消息按钮。 Second is the reply feature.
其次是回复功能。
When a user sends a message, they select them from the dropdown box. 用户发送消息时,他们从下拉框中选择它们。 So its like
<option value ="id">
and it displays the username. 因此,它类似于
<option value ="id">
,并显示用户名。
When using a message me button, I assume I need to post the username and select it from the list. 使用“给我发送消息”按钮时,我假设我需要发布用户名并从列表中选择它。 When replying, again I post the username and it selects it from the list?
回复时,我又发布了用户名,并从列表中选择了该用户名?
<form method='post' action='<?php echo $_SERVER['PHP_SELF']; ?>?p=new'>
<input type='hidden' name='rfrom' value='<?php echo $row['username']; ?>' />
<input type='hidden' name='rsubject' value='Re: <?php echo $row['title']; ?>' />
<input type='hidden' name='rmessage' value='Re: <<?php echo $row['message']; ?>>' />
<input type='submit' name='reply' class="button" value='Reply' />
</form>
This is the reply code. 这是回复代码。 As you can see, I pass the username through as
$_POST['rfrom']
如您所见,我将用户名作为
$_POST['rfrom']
I came up with the following code to select the user from the list. 我想出了以下代码,从列表中选择用户。
$fromname=(isset($_POST['rfrom'])) ? $_POST['rfrom'] : ''; //ought to validate $_POST
$selected=($u==$fromname) ? 'selected="selected"' : '';
echo "<option value='$uid'>$u</option>";
This doesn't work and when I click Reply, I just get the first user on the list. 这是行不通的,当我单击“答复”时,我只是列表中的第一个用户。
Also, could someone confirm if I could use the id to do this instead of the username? 另外,有人可以确认是否可以使用ID代替用户名来执行此操作吗? It would be easier when using the button to send a new message from a user's profile.
使用该按钮从用户个人资料发送新消息时会更容易。
Thankyou for reading, I hope you can help! 感谢您的阅读,希望能对您有所帮助!
I am now passing the user id through using $_POST['rfrom']
. 我现在通过使用
$_POST['rfrom']
传递用户ID。
The user id will be the option value. 用户ID将是选项值。
Still, I cannot get the correct user to be selected in the list. 不过,我仍然无法在列表中选择正确的用户。
Someone please help! 有人请帮忙!
我绝对会在表单的POST中使用userId,并在另一端将其验证为INT,这也将防止Drop O'Tables之类的名称破坏表单。
You forgot to include $selected
when you're outputting the select box options. 在输出选择框选项时,您忘记了包含
$selected
。
Change: 更改:
echo "<option value='$uid'>$u</option>";
To: 至:
echo "<option value='$uid' $selected>$u</option>";
There is a firefox bug in which it does not recognize selected="selected"
properly when refreshing pages or using the browser back button. Firefox中有一个bug,在刷新页面或使用浏览器后退按钮时,它无法正确识别
selected="selected"
。 Test this in other browser to make sure it's your code that actually is the problem. 在其他浏览器中对此进行测试,以确保实际上是问题所在。
Copied verbatim from Mozillazine: 从Mozillazine复制的逐字记录:
Hold down the Shift key while pressing the Reload button.
按下Shift键的同时按下Reload按钮。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.