?
Solved

getting the contents of a form

Posted on 2003-03-25
23
Medium Priority
?
140 Views
Last Modified: 2010-04-09
I have a form with a input field the unique thing with this input field is that the name contains a space in between.
<INPUT name="first name">
NOw if i have a space in between the name i cannot fetch the value of this input field on the next page.
Sample code in PHP. You can try any language
<HTML>
<HEAD><TITLE></TITLE></HEAD>
<BODY bgColor=lightgoldenrodyellow>
<form name="test" action="try3.php" method="POST">
<TABLE cellSpacing=0 cellPadding=0 width="75%" border=0>
  <TR>
    <TD>Name</TD>
    <TD><INPUT name="first name"><BR></TD>
  </TR>
  </TABLE></P>
<P>&nbsp;</P>
<input name=submit value=Send type=submit>
</form>
</BODY>
</HTML>

try3.php
<HTML>
<HEAD><TITLE></TITLE></HEAD>
<BODY bgColor=lightgoldenrodyellow>
<?php
$s = trim($_POST['first name']);
echo $s;
//$s = trim($_POST['first+name']);
//echo $s;
?>

</BODY>
</HTML>

Thank You
0
Comment
Question by:chopra_rr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
  • 4
  • +4
23 Comments
 
LVL 17

Accepted Solution

by:
dorward earned 100 total points
ID: 8203738
Solution:
Don't put a space in the name, if you want a seperator use an underscore of camal case!

<INPUT name="first_name">
<INPUT name="firstName">

Reason:
Control names are not allowed to contain spaces in HTML.

From the HTML specification:
http://www.w3.org/TR/html4/types.html#type-cdata

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

0
 

Expert Comment

by:mythreyiv
ID: 8204385


Hi chopra,

while giving  html names u shouldnot put space between them ,use any seperator if you want.
but you can use genral JAVA convention

java variable names start with small letter any break occures  we have to put the capitla letter
so firt name can me modified as
  firstName.

u can follow this convention
or you can use some seperator first-name like this.

Mythreyi
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 8204681
I don't know anything about PHP ... but can you create a string variable and use that instead?

str = 'first name';
$s = trim($_POST[str]);


or maybe:  str = 'first%20name';
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:dorward
ID: 8204737
knightEknight: No, because you can't have spaces in the name in the first place.
0
 
LVL 6

Expert Comment

by:CyberGhost
ID: 8209878
Why doing things simmilar if they can be done hard, no? It is not recommended (and not not functional in your case) to use spaces in variable name. You can see it on your own. Just put "_" instead of space to that variable and it will be fully accessible.

regards
0
 
LVL 17

Expert Comment

by:dorward
ID: 8209897
Not recomended? It is FORBIDDEN to use spaces in names of form elements. Not "It's a bad idea", but "You must not do it."
0
 
LVL 6

Expert Comment

by:CyberGhost
ID: 8209995
Oh sorry... I wanted to say is softly. Think I missed the idea ;o)
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 8210245
I assume you mean it is forbidden when using PHP.
0
 
LVL 1

Expert Comment

by:drn
ID: 8210256
just use the underscore ( _ )
0
 
LVL 17

Expert Comment

by:dorward
ID: 8210475
knightEknight: No, it is forbidden when using HTML (that's why I quoted the HTML spec in my inital comment). It doesn't matter what you process the data with at the back end. HTML form elements can not have spaces in the name.
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 8211199
I disagree on a technicality only.  I agree that it is not good practice and not straight with the HTML specs -- but it can be done.  I don't know if it will work with PHP, but it certainly works with javascript and ASP:


<HTML>
<BODY>
<FORM name='myform' method='post' action='mytest.asp'
      onsubmit='alert(this.elements["test 2"].value);return true;' >
<INPUT type='text' name='test1' value='test1' />
<INPUT type='text' name='test 2' value='test 2' />
<INPUT type='submit' />
</FORM>
</BODY>
</HTML>



then in mytest.asp:

<HTML>
<BODY>
<BR /><%=request("test1")%>
<BR /><%=request("test 2")%>
</BODY>
</HTML>


I'm quite certain it will work with JSP and CGI as well.  

Anyway, I'm not trying to start an esoteric argument, I just think that if it can be done in these other technologies, perhaps it can be done in PHP as well -- I just don't know how.

0
 
LVL 33

Expert Comment

by:knightEknight
ID: 8211205
( "test 2" has a space in it above -- "test1" does not. )
0
 
LVL 17

Expert Comment

by:dorward
ID: 8211909
It can be done? So you've tested it, and every browser accepts the invalid input?
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 8212766
well ... I don't know of a browser that accepts everything.  But certainly the latest versions of the most popular browsers will work with the code above -- as tested.  :>)
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 8212782
I know that the above works with IE4+ and NS4+.
0
 
LVL 6

Expert Comment

by:CyberGhost
ID: 8216379
W3C (World Wide Web Consortium):
www.w3c.org (international organization that certify HTML and other web standards) has accepted this variant:

"ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".")."

... there is no word about it can be followed by " " (space). So maybe this will solve your "technical" problem.

regards
0
 
LVL 6

Expert Comment

by:CyberGhost
ID: 8216398
Sorry u guyz... I've missed that you wrote it above.
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 8217706
yes, I accept that -- but that doesn't change the fact that if you put spaces in the element names, it still works :)
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 8217720
but you must quote the name in the tag:

   <INPUT  name="test  2"  type="text"  ...

instead of:

   <INPUT  name=test  2  type=text   ...
0
 

Expert Comment

by:msdickerson
ID: 8219727
I think the problem here is that most parsers used to get POST data will use a space as a seperater.  This of course causes problems like what was seen.  Some languages can get around it and some can't.  Variable names with spaces will cause problems depending how they are parsed.  Perl and PHP by default tend to use spaces as string delimiters, but can be reconfigured to use something else.  JSP, Javascript, and other languages can be manipulated also to use something else as delimiters.  CGI is not a language so it has nothing specific to it, any language can be a CGI so long as it supports the appropriate IO.  I am not a Microsoft programmer, so will not comment on ASP and .net languages.  


I simply think the best bet is to make the variable names not have spaces as earlier suggested - Unix world people like the "_"  character and old mainframers like the "-".  Or just clump the names together with no delimiters.  

If you need definition for a user interface as in your example:
<TD><INPUT name="first name"><BR></TD>
Then I would code it something like this:
<TD>First Name<INPUT name="first_name"><BR></TD>


Good luck
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 8820602
This question has been classified abandoned. I will make a recommendation to the
moderators on its resolution in a week or two. I appreciate any comments
that would help me to make a recommendation.

<note>
Unless it is clear to me that the question has been answered I will recommend delete.  It is possible that a Grade less than A will be given if no expert makes a case for an A grade. It is assumed that any participant not responding to this request is no longer interested in its final disposition.
</note>

If the user does not know how to close the question, the options are here:
http://www.experts-exchange.com/help/closing.jsp


Cd&

0
 
LVL 17

Expert Comment

by:dorward
ID: 8821636
recommendation: Points to me. Problem explained. Solution suggested. Evidence provided.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 9015923
interesting thread.  Points for the "technically correct" solution

It is time to clean this abandoned question up.

I am putting it on a clean up list for CS.

<recommendation>
points to dorward

</recommendation>

If anyone participating in the Q disagrees with the recommendation,
please leave a comment for the mods.

Cd&

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question