0

Ok I have a form on my page where people enter specific data. Then I want that data to be taken to a php page on my server that takes the form data and appends it to a url but either performs the function in a new window (I prefer the url to be hidden but not necessary) or performs the action without directing to the url (ie the url is opened but doesn't appear to the user)

Ex say I have 5 fields in the form so the base url is example.com/ and I want once the fields are entered to direct to example.com/field1&field2&field3&field4&field5

I have been able to get the action to perform with getelement codes but it opens in the same window and clears the form when they go back. I would prefer that the form stay so they can re-enter new information and continue to perform the url action.

This is what I have come up with so far for what Im looking for but It wont perform the action I get a server issue.

FORM:

<form method="post" action="http://gamerzacademy.com/trsrequest.php" target="blank">
<input type="text" name="ids" />
<input type="hidden" name="tab_clicked" value="Cafe" />
<input type="hidden" name="request_id" value="100172873469866" />
<input type="text" name="signed_request" />    <
<select name="gid" name="gid">
<option value="8631">Drums    </option>
<option value="8632">Guitar Strings    </option>
<option value="8633">Drumsticks    </option>
<option value="8634">Guitar Straps    </option>
<option value="8635">Microphones    </option>
<option value="8636">Speakers    </option>
<option value="8637">Handle Bar    </option>
<option value="8638">Spark Plug    </option>
<option value="8639">Leather Seat    </option>
<option value="8640">Motor Oil    </option>
<option value="8641">Metallic Paint    </option>
<option value="8642">Welding Torch     </option>
</select>
<input type="hidden" name="today" value="1" />
<input type="hidden" name="time" value="1345953369" />
<input type="hidden" name="ref" value="gift_today" />
<input type="hidden" name="cafe_token" value="OAlF7gSlMbQxAtBhvnprTyCLwuJFvNnvHwDcqeIrZ2YIofJzlyiZ2%2FVvflh2ih24wK1TsWdSyBH0xR205Q9+WwR%2F6ckIv4ozN4YdVvvWP2NmFlq95685hw%3D%3D" />

..... more fields .....

</form>

PHP

<?php
header("Location: http://fb-0.cafe.zynga.com/current/iframe//mfs_sent.php?'.'$_GET['ids'].'.'$_GET['tab_clicked'].'.'$_GET['request_id'].'.'$_GET['signed_request'].'.'$_GET['gid'].'.'$_GET['today'].'.'$_GET['time'].'.'$_GET['ref'].'.'$_GET['cafe_token'].'.'$_GET['from_page'].'.'$_GET['kingdom'].'.'$_GET['phylum'].'.'$_GET['uid'].'.'$_GET['sendkey'].'.'$_GET['mode'].'.'$_GET['trs_key'].'.'$_GET['stage'].'.'$_GET['mfs_time'].'.'$_GET['snood'].'.'$_GET['hash'].'.'$_GET['limiter_channel'].'.'$_GET['limiter_type'].'.'$_GET['ajax'].';"
?>

However I get this error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/15/9484115/html/trsrequest.php on line 2

1
  • I have changed the PHP to $_POST instead of $_GET and that didnt work either Commented Aug 30, 2012 at 22:36

2 Answers 2

1

Your header function should be like:

<?php
header("Location: http://fb-0.cafe.zynga.com/current/iframe//mfs_sent.php?".
urlencode($_POST['ids'])."&".
urlencode($_POST['tab_clicked'])."&".
urlencode($_POST['request_id'])."&".
urlencode($_POST['signed_request'])."&".
urlencode($_POST['gid'])."&".
urlencode($_POST['today'])."&".
urlencode($_POST['time'])."&".
urlencode($_POST['ref'])."&".
urlencode($_POST['cafe_token'])."&".
urlencode($_POST['from_page'])."&".
urlencode($_POST['kingdom'])."&".
urlencode($_POST['phylum'])."&".
urlencode($_POST['uid'])."&".
urlencode($_POST['sendkey'])."&".
urlencode($_POST['mode'])."&".
urlencode($_POST['trs_key'])."&".
urlencode($_POST['stage'])."&".
urlencode($_POST['mfs_time'])."&".
urlencode($_POST['snood'])."&".
urlencode($_POST['hash'])."&".
urlencode($_POST['limiter_channel'])."&".
urlencode($_POST['limiter_type'])."&".
urlencode($_POST['ajax']));
?>

Or you can do:

<?
$urlArgs = http_build_query($_POST);
header("Location: http://fb-0.cafe.zynga.com/current/iframe//mfs_sent.php?".$urlArgs);
?>

Note that this creates a parameter string that is key-value pairs though.

Sign up to request clarification or add additional context in comments.

10 Comments

you can remove all single quotation like this :$_GET[ids] When that is inside double quotation : " : "location:...?$_GET[ids]&$_GET..."
I know that variable substitution works inside double quotes for array just like it does for normal variables..I'm just more comfortable quoting to array indexes and closing/opening double quotes when encountering variables - just personal preference.
I recommend using http_build_query().
@Barmar: Yes that is a good function anytime you want to generate a url string since it takes care of stuff like escaping. Nice recommendation, I have updated that in the answer as well.
Well Im very new to PHP so any ideas are very helpful thank you I have tried what was posted above and tested but no matter what is entered in the forms this is where im directed fb-0.cafe.zynga.com/current/iframe//…
|
0

You are using a string in double quotes ", but when concatenating you are using single quotes '.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.