简体   繁体   中英

Messaging issues!

I have a functioning messaging script. What I am trying to do is allow 2 extra things.

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.

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']

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? 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!

EDIT

I am now passing the user id through using $_POST['rfrom'] .

The user id will be the option value.

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.

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. Test this in other browser to make sure it's your code that actually is the problem.

Copied verbatim from Mozillazine:

Hold down the Shift key while pressing the Reload button.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM