News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

more input in the Post form question

Started by Anguz, August 04, 2003, 04:59:02 PM

Previous topic - Next topic

Anguz

in Post, there's this line to input the $subject:
<font size="2"><input type="text" name="subject" value="' . addcslashes($form_subject, '"') . '" size="40" maxlength="80" /></font>

if I want to add an extra input with another name, should I also change the variable inside addslashes() to match the name?
Cristián Lávaque http://cristianlavaque.com

[Unknown]

Only if you want it prefilled...

-[Unknown]

Anguz

ah! I understand now!  ;D

thx :)

would it be too much to ask you the code for the extra fields in the post form for the Other Help forum in yabbse.org? that's pretty close to what I'm trying to do  ;)
Cristián Lávaque http://cristianlavaque.com

Spaceman-Spiff

to add a field, you'll need to adda column in the message table
also some validation in Post2()
what exactly do you want to add?
check my 'now listening to' mod, and modify that for your need

Anguz

thanks Spaceman-Spiff :)

I checked your mod but it isn't really what I'm trying to do, I don't want to save the extra info separately in the db

the thing is I have a board in my forum to post articles taken from other webpages related to the artists that forums are dedicated to

since they are posted in an order different than the one they were published in and I also don't want them to change their order due to replies, I changed that board to be ordered by subject

to make it work I have to have subjects start with the publishing date at least, but I also want to have the source of the article and the article's title, like this:

yy-mm-dd source "title"

I've asked my members several times, but they just don't follow this... so I want to have extra fields in Post.php so that they HAVE to input that data (like in the Other Help board in yabbse.org) and have a javascript make them add this information before submitting

so I have three dropdown menus for the date (year, month, day) and a text field for the article source, right before the normal subject field

then in Post2 I need to add the extra fields at the beginning of the subject, before saving it to the db and just save it normally and that's it

I more or less have worked out most of it, at least the form part... now I will check how you did the JsValidate mod and try to use it with those fields and then format the subject in Post2

if I run into trouble, I'll post here  :)

thank you guys for your help!
Cristián Lávaque http://cristianlavaque.com

Spaceman-Spiff

i see
if you wanna see what i did for the support board in yse.org, check the Post.php changes in this package: http://www.immortalshades.com/spaceman/mods/Support_Board_YSE_v1.3.zip

Anguz

#6
thank you for that code, now I know how to enable something in some boards from the admin area  :)

but I don't think I'll use the db for this hack... I already have the form working



this is the code to format the subject:
   if ($board == 30) #test forum
      $subject = $subject_year . '-' . $subject_month . '-' . $subject_day . ' ' . trim($subject_source) . ' "' . trim($subject) .'"';


if I just post the new thread, it's formatted correctly, but if I preview it first, then the previed subject line is fine, but when posting it applies the changes again, same if I preview more than once... like this:

just post: 03-02-15 Daily News "SMF rocks!"
preview+: -- "03-02-15 Daily News "SMF rocks!""

you can register and use the test board if you want:
http://llama.lewismedia.com/~anguz/forums/index.php?board=30

what can I do so that it'll just format the subject the first time and then work normally the others?
Cristián Lávaque http://cristianlavaque.com

Spaceman-Spiff

i think this code will be better:
$subject = $subject_year . '-' . $subject_month . '-' . $subject_day . ' ' . trim($subject_source) . " \n\n\"" . htmlspecialchars(trim($subject)) .'"';
added line breaks and htmlspecialchars (important for security)

Quotewhat can I do so that it'll just format the subject the first time and then work normally the others?
check my code in Post.php

Anguz

I did it! ;D

I read your code again and found something that helped me solve it all... I couldn't do it like you, cause yours was right before saving it to the db, but I was putting the subject string together much earlier and then handling it like a normal subject

but, I found the condition to check if the thread was new ($threadid == ''), so I used that to know when to show the new fields in the form (before they were showing when replying to the thread too)

and together with the new fields, I added <input type="hidden" name="subject_format" value="true"> and passed it to post2 to format the subject and then change it to false, that way it won't format the string again

thank you for your help!! ;D

I still haven't figured out how to make the person fill the extra fields before submitting with JavaScript, but it'll have to stay without it for now, cause I know cero JS  :(
Cristián Lávaque http://cristianlavaque.com

Spaceman-Spiff

check the js in the <form tag in onsubmit event

Anguz

YEAH!!! THANK YOU!!

I was looking at the submit button tag, hadn't checked the form one :P

it's working great now, I even added a new txt line in the lng file for that particular form :)

arigatou gozaimazu! ^^
Cristián Lávaque http://cristianlavaque.com

Spaceman-Spiff


Anguz

#12
this is my code for the dropdown menus... I know it can be done using arrays, how would that be?

            <td>
               <select name="subject_year">
                  <option value="">Año</option>
                  <option value="">------</option>
                  <option value="02">2002</option>
                  <option value="03">2003</option>
                  <option value="04">2003</option>
               </select>
               <select name="subject_month">
                  <option value="">Mes</option>
                  <option value="">------</option>
                  <option value="01">01</option>
                  <option value="02">02</option>
                  <option value="03">03</option>
                  <option value="04">04</option>
                  <option value="05">05</option>
                  <option value="06">06</option>
                  <option value="07">07</option>
                  <option value="08">08</option>
                  <option value="09">09</option>
                  <option value="10">10</option>
                  <option value="11">11</option>
                  <option value="12">12</option>
               </select>
               <select name="subject_day">
                  <option value="">Día</option>
                  <option value="">------</option>
                  <option value="01">01</option>
                  <option value="02">02</option>
                  <option value="03">03</option>
                  <option value="04">04</option>
                  <option value="05">05</option>
                  <option value="06">06</option>
                  <option value="07">07</option>
                  <option value="08">08</option>
                  <option value="09">09</option>
                  <option value="10">10</option>
                  <option value="11">11</option>
                  <option value="12">12</option>
                  <option value="13">13</option>
                  <option value="14">14</option>
                  <option value="15">15</option>
                  <option value="16">16</option>
                  <option value="17">17</option>
                  <option value="18">18</option>
                  <option value="19">19</option>
                  <option value="10">20</option>
                  <option value="21">21</option>
                  <option value="22">22</option>
                  <option value="23">23</option>
                  <option value="24">24</option>
                  <option value="25">25</option>
                  <option value="26">26</option>
                  <option value="27">27</option>
                  <option value="28">28</option>
                  <option value="29">29</option>
                  <option value="10">30</option>
                  <option value="11">31</option>
               </select>
            </td>


I mean, it works fine, but I'd like to learn the php way to do it :)
Cristián Lávaque http://cristianlavaque.com

۞

#13
Basically you need to load each value into an array and use a loop


$MyArray[1] = 'Value 1';
$MyArray[2] = 'Value 2';
...etc...
$MyArray[54] = 'Value 54';


Then you use a for loop:



for ($i = 1; $i <= 54; $i++) {
   print "<option value=\"\$MyArray[$i]">$MyArray[$i]</option>";
}

TTTTTT  OOOOOO MMMMMM   BBBBBB


۞

#14
FYI, If you need to display a different value than what the value is then you'll need 2 arrays. Like so:


$DisplayedArray[1] = '2001';
$DisplayedArray[2] = '2002';
...etc...
$DisplayedArray[54] = '2054';

$ValueArray[1] = '01';
$ValueArray[2] = '02';
...etc...
$ValueArray[54] = '54';

for ($i = 1; $i <= 54; $i++) {
  print "<option value=\"$ValueArray[$i]\">$DisplayArray[$i]</option>";
}

TTTTTT  OOOOOO MMMMMM   BBBBBB


Anguz

aaah... I see...

is it possible to add all the values of the array in a single line, instead of a line for each value?
Cristián Lávaque http://cristianlavaque.com

۞

Yes, you can use it like this:


$MyArray  = array(1 => 'Value 1', 'Value 2', 'Value 3');


go here for more info:

http://www.php.net/manual/en/function.array.php
TTTTTT  OOOOOO MMMMMM   BBBBBB


Anguz

#17
so I could do it like this:

$month_list = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
for ($i = 0; $i <= 11; $i++) {
   echo '<option value="' . $month_list[$i] . '">' . $month_list[$i] . '</option>\n\r';
}


right? :)

thank you very much for your help ;)
Cristián Lávaque http://cristianlavaque.com

۞

I *think* that should work, I forget how arrays work in php, I've gotten too used to delphi :P Try it and see.
TTTTTT  OOOOOO MMMMMM   BBBBBB


Advertisement: