Locked subject field.

Started by dtm.exe, September 11, 2005, 09:21:43 PM

Previous topic - Next topic

dtm.exe

How would I go about making it so that the reply subject field (the one with "Re: Locked subject field.") is visable but not editable?  I want to make it this way so that users can not change the subject of the reply.

TLM

Umm not looking but would say Post.template, and would guess there is something to indicate its a reply when you could use as the toggle to put the code for a locked field.

dtm.exe

Quote from: TLM on September 11, 2005, 11:15:45 PM
Umm not looking but would say Post.template, and would guess there is something to indicate its a reply when you could use as the toggle to put the code for a locked field.

Yes, but how would I make that field *uneditable*?

Rudolf

In Post.template.php search for:

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


And replace with:

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


Rudolf
I will update all my mods in the next few weeks. Thanks for your patience.

SVG-Collapse (you need an SVG compliant browser)

dtm.exe

Quote from: rudiksz on September 11, 2005, 11:27:48 PM
In Post.template.php search for:

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


And replace with:

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


Rudolf

Works LIKE A CHARM!  Can't thank you enough, man :).

Rudolf

I will update all my mods in the next few weeks. Thanks for your patience.

SVG-Collapse (you need an SVG compliant browser)

juglesh


Or replace it with this:
<td>
<input type="hidden" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', '  />
<B>'.$context['subject'].' </B>
</td>


Then it wont look like you can edit it.

j

juglesh

WHOOPS!!! :-X

That aint gonna work.  It wont let you put a subject on a new post that way!
How's this:

if ($context['subject'] == ''){
echo '<input type="text" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', ' size="80" maxlength="80" tabindex="1" />';
}else{echo'<input type="hidden" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', '  />
<B>'.$context['subject'].' </B>';
}

Rudolf


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


Rudolf
I will update all my mods in the next few weeks. Thanks for your patience.

SVG-Collapse (you need an SVG compliant browser)

Ciced

Hi all, I'm using the following code to hide the subject field when the user is replying to a topic:

if ($context['subject'] == '')
echo '<tr><td align="center"><b', isset($context['post_error']['no_subject']) ? ' style="color: #FF0000;"' : '', '>', $txt[70], ':</b><input type="text" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', ' size="80" maxlength="80" tabindex="1" /></td></tr>';


However, the problem comes when the user is creating a new topic and clicks the Preview button. Since the subject is no longer empty it removes the subject field which is unwanted. Does anybody know how to check if the post is a preview?

Ciced


Thantos

You can use:  empty($context['current_topic']) to determine if its a new topic or not.

Ciced

Thanks a lot Mick, works great. :D

Enc0der

#13
Hi

That's a really great trick, but the only problem is that it won't allow the thread-starter or the moderator to edit the thread's (first message) subject.

Basically we need (is_first_message) instead of empty($context['current_topic'])...

any help with that ?

Elmacik

Enc0der, we dont need is_first_topic we have one anyway :)
Its $context['first_message']
This variable will return the first message's id in the current topic.
So if you want to use for the first messages of every page in a topic, use this;
if ($message['id'] == $context['first_message']) echo ' this is the first message of this page';
Or if you want to find the individual first message of a topic use this;
if ($message['counter'] == '0') echo ' this is the first message of this topic';
Home of Elmacik

Enc0der

Thanks! but.. it doesn't seem to work..

for testing,
echo '<!-- ', $message['id'], ' != ', $context['first_message'], ' -->'
returned:
<!--  !=  -->

I use SMF 1.1 RC2.

Elmacik

It wont return because you dont print them...
Use the ways I told you.
If you want to see the numbers only, then use;
echo $messge['id']; echo $context['first_message'];
Home of Elmacik

Enc0der

#17
I did it for testing only...

I tried this:

<input name="subject"', ($message['id'] != $context['first_message']) ? '' : ' value="' . $context['subject'] . '"', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80"' , ($message['id'] != $context['first_message']) ? 'type="hidden" /> <b>' . $context['subject'] . '</b>' : 'type="text" />', '

But it simply had no effect, because they both empty so they equal..

We're talking about Post.template.php, right? I want to replace the subject field with plain text on the "post reply" page, so silly users won't change the message subject in the middle of the thread.

empty($context['current_topic']) worked,
<input name="subject"', empty($context['current_topic']) ? '' : ' value="' . $context['subject'] . '"', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80"' , (!empty($context['current_topic'])) ? 'type="hidden" /> <b>' . $context['subject'] . '</b>' : 'type="text" />', '
but then I (as an admin/moderator) or the thread's starter could not change the first-message's subject after it as been posted..

Elmacik

It wont work because you are setting an empty value for the subject, you are not locking it.
Use this instead;

<input type="text" name="subject" value="', $context['subject'], '" ', $message['counter'] == '0' ? '' : 'disabled="disabled"' tabindex="', $context['tabindex']++, '" size="80" maxlength="80" />

This code should do;
If user is editing the first message, it should let him/her change the subject. But if its not the first message, then the sucject field will be locked and wont let anyone edit it.
Home of Elmacik

Enc0der

#19
QuoteIt wont work because you are setting an empty value for the subject, you are not locking it.
I don't, I use type="hidden", and then output it as plain-text just for convenience..

In your code you should use "readonly", not "disabled".. (as you'll get a 'no subject' error) ;)
and you're also missing a comma before ' tabindex=

But anyway, it doesn't work.. :-\
Your code makes it always read only..

$message['counter'] is empty, I have no doubt about that.. I think we can access it only on Display.template, and not Post.template.. :-\

Advertisement: