input variable is truncated if a space is on the string

ajw3208 08 Jun, 2009
Hi all,

Can anyone shed any light on why when an input field in a form is submitted, the target form displays the variable OK (after retrieval using $_POST) but after reconstructing the received variable into a hidden field for submission onto another form, the variable is truncated if a space is in the string?

first form - the input field
<INPUT TYPE=TEXT NAME="playerAddress" title="Required" SIZE=60 MAXLENGTH=60>
test input = test text

the receiving form. 1st line grabs received variable from $_POST for passing onto a downstream form. 2 line display variable in the page

<input type=hidden name="playerAddress" value=<?php echo $_POST["playerAddress"];?>>
Address: </B></I><?php echo $_POST["playerAddress"];?>

received value = test text (all godd so far)

3rd form variable display code.

Address: </B></I><?php echo $_POST["playerAddress"];?>

received value = test (opps, whwre is the word text?)

aj
GreyHead 08 Jun, 2009
Hi ajw3208,

You need to add quotes round the value - if you check the form html I think you will find you have value=test text. Try this
<input type='hidden' name='playerAddress' value='<?php echo $_POST['playerAddress']; ?>' />


Bob

PS It's safer to use the filtered values that Joomal provides with JRequest than to use $_POST
<input type='hidden' name='playerAddress' value='<?php echo JRequest::getString('playerAddress', '', 'post'); ?>' />


PPS You'll see that I prefer single quotes as this lets me use
echo "<input type='hidden', name='some_name' . . ./>";
but either will work as long as you keep them all consistent.
ajw3208 10 Jun, 2009
Bob,

thank you. isn't it strange how things don't work when the tag syntax is incorrect. This error prompted a quick review of other code and sad to say other mistakes were found. 😶

on the bright side, at least they were found

aj
ajw3208 10 Jun, 2009
Hi Bob,

I tried the Jrequest version as you suggested above and BANG!
Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM, expecting ',' or ';' in /home/wphcfc/public_html/z-wphctesting/components/com_chronocontact/chronocontact.html.php(141) : eval()'d code on line 2

Code for line 2 as indictaed above
<input type="hidden" name="playerRegNum" value="<?php echo $JRequest::getString('playerRegNum','','post');?>" />


Any idea why

aj
GreyHead 10 Jun, 2009
Hi aj,

Yes, sorry, I left an extra $ in there - it should be plain JRequest::get. . . (my earlier post is now corrrected).

Bob
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger