PDA

View Full Version : Add checkbox


mad@Max
11-03-2008, 09:49 PM
I need add checkbox in newthread, newreply, editpost. If checkbox checked in new cell of table "post" adding value "1", unchecked - value "0".
So, how i may did that?

mad@Max
11-27-2008, 02:41 PM
I'll try explain...
Im little rewrite news module (vbadvanced), for last posts:
$getnews = $db->query_read("
SELECT $ratingsql user.*, thread.threadid, post.title, thread.title, thread.replycount, post.username AS puname, post.userid AS puid, postusername, postuserid, post.dateline AS postdateline, sticky, thread.attach, thread.lastpostid, thread.lastposter, thread.lastpost, IF(views<=thread.replycount, thread.replycount+1, views) AS views, thread.forumid, post.postid, pagetext
$vba_news_fields
FROM " . TABLE_PREFIX . "thread AS thread
LEFT JOIN " . TABLE_PREFIX . "post AS post ON (post.postid = thread.lastpostid)
LEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = post.userid)
$vba_news_join
WHERE thread.threadid IN(" . implode(',', $newstids) . ")
" . iif(!$threadsqueried AND $mod_options['portal_news_cutoffdate'], 'AND thread.dateline > ' . (TIMENOW - ($mod_options['portal_news_cutoffdate'] * 86400))) . "
" . iif($ignusers, 'AND thread.postuserid NOT IN(' . $ignusers . ')') . "
" . iif($mod_options['portal_applypermissions'], $forumperms_query) . "
AND rel_yn = 1
ORDER BY " . iif($mod_options['portal_news_sticky'], 'sticky DESC, ') . $mod_options['portal_news_orderby'] . " $mod_options[portal_news_direction]
" . iif($limitapplied, 'LIMIT ' . ($mod_options['portal_news_maxposts'] + $mod_options['portal_news_enablearchive']), $newslimit) . "
");
Where "rel_yn" is custom added cell of "post" table, with values 0 and 1. So, if post have value = 1 message showing on main page, else not showing.
The case for small, add checkbox in posting form, where you can choose send message on main page or not (check or uncheck checkbox).
So, how did this?
Checkbox in template:
<label for="cb_rel_yn"><input type="checkbox" name="rel_yn" value="1" id="cb_rel_yn" tabindex="1" $checked[rel_yn] />Send this message on main page?</label>
In attach screenshot how it will be look and product where i was trying realise this...
Pls help.

Lynne
11-27-2008, 03:34 PM
I think you've done what you need to do, but you didn't say if you already added the column rel_lyn to your database. What is the result of what you have done so far?

mad@Max
11-27-2008, 04:42 PM
I already added column rel_lyn, i want make work this checkbox.
It worked just on unchecked selection, in column add value 0 just in new post. But if you check it, rel_lyn column will be rewrited in all post as value 1...

mad@Max
11-30-2008, 03:57 PM
bump

Lynne
11-30-2008, 04:14 PM
So, it is set to "0" unless someone checks the box, in which case it is set to "1". That is what you want, right? But, instead, what is happening?

mad@Max
11-30-2008, 04:22 PM
Instead that, when you check the box, rewrited all values in column rel_yn...

Lynne
11-30-2008, 04:35 PM
What does your write/update statement look like? It sounds like your script is written incorrect if it is changing every column instead of just the column for that post.

mad@Max
11-30-2008, 04:43 PM
I attach plugins in second post, how i did this.
Changing just one column, rel_yn. So, if you leave box not checked - rel_yn vill be changed on 0, in the new post, if you check the box - rel_yn will be changed in all post.

Lynne
11-30-2008, 04:50 PM
You need a where statement in here:
if($post['rel_yn']) // true
{
$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "post SET rel_yn = 1 WHERE postid=$postid
");
}else{ // false
$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "post SET rel_yn = 0 WHERE postid=$postid
");
}I don't know that "WHERE postid=$postid" is the correct way to write it, but you need to update the table only where the postid is equal to the post you are submitting. If you added that to the post table, you should be able to just use the datamanager to set it. Something like:
$threadman->set('rel_yn', $vbulletin->GPC['rel_yn']);First you need to clean the variable and then set it in the correct place (I didn't look to see if newpost_complete is the correct location). It just needs to be before there is a statement like this instead of what you are doing (adding a query):
$threadman->save();