[REPORTED] problem with 0 in generate_text_for_display

Discussion forum for MOD Writers regarding MOD Development.
Locked
User avatar
woipi90
Registered User
Posts: 908
Joined: Mon Feb 16, 2009 5:32 pm
Location: Austria

[REPORTED] problem with 0 in generate_text_for_display

Post by woipi90 »

hy all,

ive got a small problem.. i hope u can help me..
ive got a customn comment system and all is just working fine when submitting a post..

but when i want to accept '0' as comment a blank comment gets submitted..

my code would be:

Code: Select all

		$("#commentform").submit(function(event) {
			event.preventDefault();
			var $form = $(this), $text = $form.find('textarea[name="comment_text"]').val();
alert($text);
			if ($text != "") {
				$.ajax({
					type: "POST",
					url: "clubs_ajax.php",
					data: {
						cid: getParameter(window.location.search.substring(1), "cid"),
						mode: "post_comment",
						comment_text: $text
					}}).done(function() {
						$form.find('textarea[name="comment_text"]').val("");
						$("#comment_sec").load(location.href + " #comment_sec > *");
						alert("{LA_CLUB_COMMENT_POSTED}");
				});
			}
			else {
				alert("{LA_CLUB_BLANK_COMMENT}");
			}
		});
as u can see here i also tryed to view if the value '0' is correctly loaded from my template through an alert..
and it seems to be allright..

Code: Select all

case 'post_comment':
				$cid = request_var('cid', 0);
				$comment_text = request_var('comment_text','', true);

				if ($comment_text != '')
				{
					$message_parser				= new parse_message();
					$message_parser->message	= utf8_normalize_nfc($comment_text);

					if ($message_parser->message)
					{
						$message_parser->parse(true, true, true, true, false, true, true, true);
					}

					$sql_ary = array(
						'club_id'         			=> $cid,
						'user_id'         			=> (int) $user->data['user_id'],
						'comment_time'       		=> time(),
						'comment_text'              => $message_parser->message,
						'comment_uid'        		=> $message_parser->bbcode_uid,
						'comment_bitfield'   		=> $message_parser->bbcode_bitfield,
					);

					$sql = 'INSERT INTO ' . CLUBS_COMMENT_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
					$db->sql_query($sql);

					$sql = 'SELECT MAX(comment_id) as m_comment_id FROM ' . CLUBS_COMMENT_TABLE;
					$result = $db->sql_query($sql);
					$coid = $db->sql_fetchfield('m_comment_id');
					$db->sql_freeresult($result);

					$comments_info = $bc->get_comment_info($coid);

					$c_sql_ary = array(
						'club_comments'		=> (int) $comments_info['club_comments'] + 1,
					);
					$sql = 'UPDATE ' . CLUBS_TABLE  . ' SET ' . $db->sql_build_array('UPDATE', $c_sql_ary) . ' WHERE club_id = ' . (int) $comments_info['club_id'];
					$db->sql_query($sql);
				}
				break;
in the hope that u can help me..


thx woipi
Last edited by woipi90 on Sun Nov 18, 2012 3:52 pm, edited 1 time in total.
My mods: Ultimate Board Clubs
Support: only for the UBCS!
-----
function be_friends($uid, $u){return ($u == $user->['user_id']) ? false : true;}
$this->be_friends($uid, $user->['user_id']) ? $allow_pm : echo "You failed again";
User avatar
ViolaF
I've Been Banned!
Posts: 1609
Joined: Tue Aug 14, 2012 11:52 pm

Re: problem with 0 in customn function

Post by ViolaF »

You mean, when you insert a 0 (zero) in the comment, the comment is blank after sending the form?
User avatar
woipi90
Registered User
Posts: 908
Joined: Mon Feb 16, 2009 5:32 pm
Location: Austria

Re: problem with 0 in customn function

Post by woipi90 »

ViolaF wrote:You mean, when you insert a 0 (zero) in the comment, the comment is blank after sending the form?
yes exactly..
My mods: Ultimate Board Clubs
Support: only for the UBCS!
-----
function be_friends($uid, $u){return ($u == $user->['user_id']) ? false : true;}
$this->be_friends($uid, $user->['user_id']) ? $allow_pm : echo "You failed again";
User avatar
DionDesigns
Registered User
Posts: 515
Joined: Sun Feb 26, 2012 11:22 pm
Location: Uncertain due to momentum.
Contact:

Re: problem with 0 in customn function

Post by DionDesigns »

Change this line:

Code: Select all

if ($message_parser->message) {
to this:

Code: Select all

if ($message_parser->message != '') {
and see if it works. Removing that conditional should also fix the problem.
User avatar
woipi90
Registered User
Posts: 908
Joined: Mon Feb 16, 2009 5:32 pm
Location: Austria

Re: problem with 0 in customn function

Post by woipi90 »

DionDesigns wrote:Change this line:

Code: Select all

if ($message_parser->message) {
to this:

Code: Select all

if ($message_parser->message != '') {
and see if it works. Removing that conditional should also fix the problem.
hm removed the if case but didnt work eighter..
My mods: Ultimate Board Clubs
Support: only for the UBCS!
-----
function be_friends($uid, $u){return ($u == $user->['user_id']) ? false : true;}
$this->be_friends($uid, $user->['user_id']) ? $allow_pm : echo "You failed again";
User avatar
woipi90
Registered User
Posts: 908
Joined: Mon Feb 16, 2009 5:32 pm
Location: Austria

Re: problem with 0 in customn function

Post by woipi90 »

oh sry i have now found the problem is within the displaying of the text '0'..

ive got:

Code: Select all

generate_text_for_display($row['comment_text'], $row['comment_uid'], $row['comment_bitfield'], 7)
there and it shows me nothing..

when i change it to:

Code: Select all

$row['comment_text']
it shows just fine..


whats the problem?


grz woipi
My mods: Ultimate Board Clubs
Support: only for the UBCS!
-----
function be_friends($uid, $u){return ($u == $user->['user_id']) ? false : true;}
$this->be_friends($uid, $user->['user_id']) ? $allow_pm : echo "You failed again";
User avatar
A_Jelly_Doughnut
Former Team Member
Posts: 34458
Joined: Sat Jan 18, 2003 1:26 am
Location: Where the Rivers Run
Contact:

Re: problem with 0 in customn function

Post by A_Jelly_Doughnut »

That would be a bug in generate_text_for_display.

Code: Select all

function generate_text_for_display($text, $uid, $bitfield, $flags)
{
	static $bbcode;

	if (!$text)
	{
		return '';
	}
In PHP:

Code: Select all

<?php
$str = '0';
if (!$str)
{
   echo "String evaluates to false\n";
}
will print "String evaluates to false.
So the code in generate text_for_display is simply returning a blank string.

Feel free to file a bug in the phpBB tracker: http://tracker.phpbb.com/
A Donut's Blog
"Bach's Prelude (Cello Suite No. 1) is driving Indiana country roads in Autumn" - Ann Kish
User avatar
AmigoJack
Registered User
Posts: 6011
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: problem with 0 in customn function

Post by AmigoJack »

A_Jelly_Doughnut wrote:file a bug
I did: PHPBB3-11216.
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
Locked

Return to “[3.0.x] MOD Writers Discussion”