Need help with form output

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rickou812
Forum Newbie
Posts: 4
Joined: Sun Jan 28, 2007 2:05 am

Need help with form output

Post by rickou812 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I need a form to contact a URL with a specific output but I do not know how to strip out the unnecessary symbols.
Here is a copy of the form:

[syntax="html"]
<form method="get" name="Request" action="http://website.com/12345/">
<input name="" value="" type="hidden">
<table align="center" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td>	
<table class="formTable" align="center" border="0" cellpadding="0" cellspacing="0">
</table>
<table class="formTable" align="center" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="label" valign="middle"><label for="">Number:</label></td>
<td align="left">
<input size="10" maxlength="10" name="/" value="" type="">&nbsp;&nbsp;</td>
</tr></tbody></table><table align="center" border="0"></tbody>
<tr><td class="globalButtons" align="right" width="100%">
<button type="submit"><b>Request</b></button></td></tr></tbody></table>
</td></tr></tbody></table>
</form>
This is what this will output:
http://website.com/12345/?%2F=10
It adds the ?%2F=
I need it to output:
http://website.com/12345/10

How can I strip out the ?%2F

Thanks,
Richard Cook


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Firstly, %2F is the URLEncode for "/"
<input size="10" maxlength="10" name="/" value="" type="">
See it?

When you use the get method, it add the field name = the field value into the url. So.. rename that field for starters.


Secondly, I don't think you should be using the get method to do this. I think you should use method="post" and action="<?=$_SERVER['PHP_SELF']?>"

Then, at the very start of the file, do a check for if the form has been submitted, and redirect to the new location

Code: Select all

header("Location: http://website.com/12345/".$_POST['fieldname']);
rickou812
Forum Newbie
Posts: 4
Joined: Sun Jan 28, 2007 2:05 am

Post by rickou812 »

It looks like your on the right track, but I still can not get it to work.
Using the post method the "entered value is not added to the URL.
The website requires the value to be entered like this:
http://www.website.com/1234/value from form output
It must not contain any symbols, only the integer added from the form.

I hope this helps clarify...
Thanks for any assistance,
Richard Cook
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Did you rename the field that you want to pass and retrieve the same name from $_POST?

BTW, the post method doesn't add any string to URL; you have to do that yourself with header()
rickou812
Forum Newbie
Posts: 4
Joined: Sun Jan 28, 2007 2:05 am

Post by rickou812 »

It just isn't clicking in my head...lol
can you modify the code above to make it work?
Thanks,
Richard
User avatar
louie35
Forum Contributor
Posts: 144
Joined: Fri Jan 26, 2007 8:40 am
Location: Dublin
Contact:

Post by louie35 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


what about removing the / from the input name. Not a very good way to name your fields:

modified code
[syntax="html"]
<form method="get" name="Request" action="http://website.com/12345/"> 
<input name="secret" value="" type="hidden"> 
<table align="center" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td>    
<table class="formTable" align="center" border="0" cellpadding="0" cellspacing="0"> 
</table> 
<table class="formTable" align="center" border="0" cellpadding="0" cellspacing="0"> 
<tbody> 
<tr> 
<td class="label" valign="middle"><label for="">Number:</label></td> 
<td align="left"> 
<input size="10" maxlength="10" name="number" value="" type="">&nbsp;&nbsp;</td> 
</tr></tbody></table><table align="center" border="0"></tbody> 
<tr><td class="globalButtons" align="right" width="100%"> 
<button type="submit"><b>Request</b></button></td></tr></tbody></table> 
</td></tr></tbody></table> 
</form> 

feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

rickou812 wrote:It just isn't clicking in my head...lol
can you modify the code above to make it work?
Thanks,
Richard
You are a php programmer, right?
Nothing I've said is much more than a beginner could handle...

Code: Select all

<?php
if(isset($_POST['number']))
{
      header("Location: http://website.com/12345/".$_POST['number']);
}

Code: Select all

<form method="post" name="Request" action="<?=$_SERVER['PHP_SELF']?>"> 
rickou812
Forum Newbie
Posts: 4
Joined: Sun Jan 28, 2007 2:05 am

Post by rickou812 »

Yeap I got it now...lol
Just was having a blond moment...

Thanks,
Richard
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Don't worry. Maybe it's me. Maybe I assume too much. :roll:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Please try to avoid double posting threads in the future rickou812.
Post Reply