views:

70

answers:

5

I have created a simple checkout form for use with a mobile website:

<form action="" method="GET">
        First Name:<br />
        <input type="text" name="firstname" />
        <br /><hr />
        Last Name:<br />
        <input type="text" name="lastname" />
        <br /><hr />
        Phone Number:<br />
        <input type="text" name="phonenumber" />
        <br /><hr />
        Address:<br />
        <input type="text" name="address" />
        <br /><hr />
        Town:<br />
        <input type="text" name="town" />
        <br /><hr />
        County:<br />
        <input type="text" name="county" />
        <br /><hr />
        Postcode:<br />
        <input type="text" name="postcode" />
        <br /><hr />
        Email:<br />
        <input type="text" name="email" />
        <br /><hr />
        <input type="submit" value="Submit" />
        </form>

The information created needs to pass in a URL only. The base URL is given, in this case, domain.com. The URL that is created and navigated to should look like: domain.com/p=firstname+lastname+123+456+7890+123+address+street+etc.....

Because this is for a mobile site, JavaScript cannot be used. PHP would be ideal as I have some knowledge, but other solutions may be possible.

Any guidance on where to start or what to research?

A: 

If it's an Apache server you're working with, you could use mod_rewrite to regex-craft the URL to anything you'd like.

littlefoot
Or IIS Rewrite, on the other end of the spectrum.
Chris
Reasonable, but I'm not sure of the server currently.
Anders H
A: 

Use method="GET" (rather than POST) to cause the browser to pass form data as part of the URL (in the form action?fieldName=value&fieldName2=value2).

SoapBox
Anders H
SoapBox
A: 

Do you have to have that exact URL format? Can't you get just change the form method to GET and use the standard query string format? If you really want that format, you can redirect on the server. Frankly, I think the regular query string is better (what if you add a field?)

Matthew Flaschen
I've been told I need that format by the website I'm referring to. What do you mean "if I add a field"?
Anders H
Say a middle name field is added. Then the new expected format will presumably be domain.com/p=firstname+middlename+lastname+123+456+7890+123+address+street+etc . If the site gets a request that is missing a field, they will not know which is missing, and may e.g. interpret lastname as the middlename data. That is why field names are important.
Matthew Flaschen
A: 

Not entirely sure what you're asking, but it seems you want the form above to submit itself to a URL with all of the variables being in the URL string. IF this is the case, you must change the method to GET. As for pulling those variables into your receiving page, PHP is fine. The syntax in PHP for grabbing get var is

$_GET["fname"]; 
chamiltongt
Right, I'm understanding that GET is necessary, but as for pulling all the variables together... I'm afraid I'm still learning.
Anders H
+1  A: 

Anders,

If you are needing to post this to another site, then you should use a redirect.

Here are the steps needed ->

  1. Post the above form to your own PHP page
  2. On that page, do a redirect to the page you need to post to with the URL string being the format you need with your variables inserted.

To do a redirect in PHP:

header( 'Location: http://www.yoursite.com/new_page.html' ) 
chamiltongt
So posting to redirect.php and on redirect.php `<?php` `$url = "http://www.domain.com?p=" . $firstname+ etc...` `header( 'Location: $url' ) ;` `?>`
Anders H
Yes exactly, this is how you would do it.
chamiltongt
Just make sure the header() call happens at the top of your php file after you read the form variables.
chamiltongt