News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Disable subject change if replying to a post (SMF 1.1.21)

Started by MobileCS, June 21, 2015, 10:14:29 PM

Previous topic - Next topic

MobileCS

I'm trying to disable users from changing the subject when replying to a post. It's almost working, but I received some unexpected behavior.

Post.template.php

Find:
<td>
<input type="text" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80" />
</td>


Replace with :
<td>';
// disable subject change if replying to a post
if (isset($context['previous_posts']) && count($context['previous_posts']) > 0)
{
echo '<input type="text" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80" disabled="disabled" />';
}
else
{
echo '<input type="text" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80" />';
}
echo '
</td>


As you can see from the code above, I just added the "disabled" parameter to the input tag. When replying to a post, the subject input box -is- disabled and the subject text is still being displayed properly. However ... after clicking the "post" button, the subject text disappears and I receive the following error :

QuoteThe following error or errors occurred while posting this message:

No subject was filled in.

Any ideas why this is happening and what I can do to fix it?

Sir Osis of Liver

The 'disabled' parameter causes the form to submit a blank field for subject, and that causes SMF to throw an error.  Use 'readonly' and it will work correctly.
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

MobileCS


MobileCS

In case anyone else wants to do this, here is the complete code :

/Themes/default/Post.template.php

Find:
<td>
<input type="text" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80" />
</td>


Replace with:
<td>';
// my edit - disable subject change if replying to a post
if (isset($context['previous_posts']) && count($context['previous_posts']) > 0)
{
echo '<input type="text" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80" class="disabled" readonly="readonly" onfocus="this.blur()" tabindex="-1" />';
}
else
{
echo '<input type="text" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80" />';
}
echo '
</td>


style.css

.disabled { background-color :#e5e5e5; border: 1px solid #BCBCBC }

Sir Osis of Liver

Or you can just do this -

Post.template.php



<input type="text" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80" class="input_text" readonly />';


Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

☠ DeadMan ☠

Nice, Krash. :)
I'll have to check to see that a friend's site gets that done.

MobileCS

Quote from: Krash on June 21, 2015, 11:43:57 PM
Or you can just do this -

Post.template.php



<input type="text" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80" class="input_text" readonly />';



I'm assuming the "input_text" class is SMF 2.x only? It doesn't exist on any of my 1.1.xx files.

☠ DeadMan ☠

1.1.x is end of life, last I knew.
Heck, 2.0.x almost is, too, with 2.1 being already in beta, and being more focused on.

Sir Osis of Liver

Yes, I pulled that from a 2.0.10 file, but it should work the same in 1.1.x if you just add the readonly parameter.
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Advertisement: