Peanut Posted February 13, 2008 Share Posted February 13, 2008 Hello I have a form within a php file that goes to a shopping cart, the form has a hidden field that should pass two variables to the shopping cart <form name=form03 action=http://www.xxxx.com/rpg/cart/easycart.php method=get enctype=multipart/form-data> <input type=hidden name=des value=$artist $title> $ artist and $title are populated from a flat file db However both $artist and $title have spaces in them as well as this there is also a space between $artst and $title $artist=ereg_replace( " ", "%20", $artist ); $title=ereg_replace( " ", "%20", $title ); Replaces the spaces in each variable but not the spaces in between the two variables ( $artist and $title ) Preffereably I would like to pass the full url including spaces to the cart by replacing all of the spaces in each variable and also the space between the two variables with %20. As you can tell I am pretty new at PHP .. Update $artist=ereg_replace( " ", "%20", $artist ); $title=ereg_replace( " ", "%20", $title ); print" <TR> <form name=form03 action=http://www.xxx.com/rpg/cart/easycart.php method=get enctype=multipart/form-data> <input type=hidden name=des value=$artist-$title> This works but my cart prints the %20 in the item description and it looks messy How can I make the form passt the full variables including spaces to the cart without replacing them with %20 At the moment I get this in my cart Francis%20Bacon-Portrait%20of%20Georeg%20Dyer%20Talking and I would like this Francis Bacon-Portrait of Georeg Dyer Talking Thanks in advance Rob Link to comment https://forums.phpfreaks.com/topic/90863-replacing-spaces-with-a-20-when-submitting-a-form/ Share on other sites More sharing options...
haku Posted February 13, 2008 Share Posted February 13, 2008 You have one major problem in all your code. You should have double quotes around all form attributes. For example, your form tag should read like this: <form name="form03" action="http://www.xxxx.com/rpg/cart/easycart.php" method="get" enctype="multipart/form-data"> I don't know if this will solve your problem for sure, but it very well may. Preffereably I would like to pass the full url including spaces to the cart Your URL (http://www.xxxx.com/rpg/cart/easycart.php) doesn't have any spaces, so this doesn't really make sense. Finally, as a side point, the 'name' attribute of forms has been deprecated, so you shouldn't use it. Link to comment https://forums.phpfreaks.com/topic/90863-replacing-spaces-with-a-20-when-submitting-a-form/#findComment-465679 Share on other sites More sharing options...
Peanut Posted February 13, 2008 Author Share Posted February 13, 2008 Thanks I had removed the " when placing the code inside a print statement now having replaced them again and added a \ in front of them it does indeed sove the problem. Thanks for the assistance Link to comment https://forums.phpfreaks.com/topic/90863-replacing-spaces-with-a-20-when-submitting-a-form/#findComment-465737 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.