Jump to content

Replacing spaces with a %20 when submitting a form


Peanut

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.