Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Bug in mathCaptcha() function  (Read 5596 times)

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
Bug in mathCaptcha() function
« on: February 18, 2007, 10:01:24 PM »

Hi, there :D

This is code from ver.1.5.31:
Code: [Select]
// MATH CAPTCHA
function mathCaptcha() {
$x = rand(1, 9);
$y = rand(1, 9);
$math = '<p><label for="c">* '.l('math_captcha').':</label>
';
$math .= $x.' + '.$y.' = ';
$math .= '<input type="text" name="calc" id="c" style="width: 30px;" /></p><p>';
$math .= html_input('hidden', 'sum', 'sum', $x + $y, '', '', '', '', '', '', '', '', '', '', '').'</p>';
return $math;
}
It uses call of function html_input(...) expecting it to return value. Unfortunately this function returns no value at all. Thus, particular input field gets echo-ed at wrong place messing up all intended output. Due to this some markup validation errors and empty paragraph.

Would be great to have html_input() function that just returns string prepared for output instead of echoing it to browser.

I fixed this as follows:
Code: [Select]
 
// MATH CAPTCHA
function mathCaptcha() {
$x = rand(1, 9);
$y = rand(1, 9);
$math = '<p><label for="c">* '.l('math_captcha').':</label>
';
$math .= $x.' + '.$y.' = ';
$math .= '<input type="text" name="calc" id="c" style="width: 30px;" /></p><p>';
   // Original code : $math .= html_input('hidden', 'sum', 'sum', $x + $y, '', '', '', '', '', '', '', '', '', '', '').'</p>';
   $xplusy = $x + $y;
   $math .= "<input type=\"hidden\" name=\"sum\" id=\"sum\" value=\"$xplusy\" /></p>";
return $math;
}
Regards,
Valdis ;)
« Last Edit: January 27, 2008, 11:15:03 PM by philmoz »
Logged

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
Bug in mathCaptcha() function
« Reply #1 on: February 19, 2007, 09:21:01 PM »

So, you are saying that the output should be along the lines of:-
<input type="hidden" name="sum" id="sum" value="10" />

This is what is appearing in my source using the original code...
« Last Edit: August 01, 2008, 10:14:47 PM by Keyrocks »
Logged
Of all the things I have lost, it is my mind that I miss the most.

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
Bug in mathCaptcha() function
« Reply #2 on: February 19, 2007, 09:31:37 PM »

By source You mean page source in browser ? If so, then does it appear inside <p></p> tags right after
previous tag - ...<input type="text" name="calc" id="c" style="width: 30px;" /></p> as intended?

For me it appears several tags earlier basically messing up intended markup. No visible damage, unless looked up through markup validator.

Regards,
Valdis ;)
« Last Edit: January 27, 2008, 11:15:50 PM by philmoz »
Logged

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
Bug in mathCaptcha() function
« Reply #3 on: February 19, 2007, 10:42:59 PM »

hmm, that's odd. The p and /p are present in the code, but seem to be getting removed....  :rolleyes:
Logged
Of all the things I have lost, it is my mind that I miss the most.

michael kennedy

  • Full Member
  • ***
  • Karma: 3
  • Posts: 207
    • SpektreDesign
Bug in mathCaptcha() function
« Reply #4 on: February 21, 2007, 11:07:06 PM »

I assume this will be added to core?

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
Bug in mathCaptcha() function
« Reply #5 on: February 22, 2007, 09:32:25 AM »

Well, that would be odd, indeed  :rolleyes:

Regards,
Valdis ;)
Logged

ld3

  • Newbie
  • *
  • Karma: 0
  • Posts: 15
Bug in mathCaptcha() function
« Reply #6 on: February 27, 2007, 05:53:52 PM »

thanks for this fix.  i just found this validation error and was dreading trying to track it down myself.
Logged

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
Bug in mathCaptcha() function
« Reply #7 on: February 28, 2007, 12:10:29 PM »

'xcuse a dumbass, I've tried many solutions now, and either I get it to validate but not send any mail, or I can send mails but not validate... How should this look to make both work ?
Quote
function mathCaptcha() {
   $x = rand(1, 9);
   $y = rand(1, 9);
   $math = '<p><label for="c">* '.l('math_captcha').':</label>
';
   $math .= $x.' + '.$y.' = ';
   $math .= '<input type="text" name="calc" id="c" style="width: 30px;" /></p><p>';
   $math .= html_input('hidden', 'sum', 'sum', $x + $y, '', '', '', '', '', '', '', '', '', '', '').'</p>';
   return $math;
}
Tha's my question to you ;)
« Last Edit: January 27, 2008, 11:16:19 PM by philmoz »
Logged
"It's only dead fish that goes with the flow... "
Updated

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
Bug in mathCaptcha() function
« Reply #8 on: March 01, 2007, 01:39:22 PM »

Hi, Patric!

I updated post above how it should look like. However, if after applying this You still have problems with e-mail sending then problem isn't with display of match captcha but somewhere else.

Regards,
Valdis
Logged

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
Bug in mathCaptcha() function
« Reply #9 on: March 01, 2007, 02:04:47 PM »

Great, codie... I'll try and see if it validates, and still works... Thanks.
Logged
"It's only dead fish that goes with the flow... "
Updated

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
Bug in mathCaptcha() function
« Reply #10 on: March 09, 2007, 04:44:23 PM »

Well, nothing wrong there... Works like a validated charm. Thanks.
Logged
"It's only dead fish that goes with the flow... "
Updated

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
Bug in mathCaptcha() function
« Reply #11 on: March 09, 2007, 10:01:28 PM »

Patric, if You are using this version then I recommend to apply this mod (Adding some security to mathCaptcha()) while next release of sNews isn't available yet.
« Last Edit: August 01, 2008, 10:16:55 PM by Keyrocks »
Logged