How to insert PHP variable into URL?

Hi,

We are trying to make a simple payment form that takes a price from a hidden field and inserts that number into a URL for WorldPay to process that payment. So far we have the form and the correct URL for a fixed price payment but ideally we'd like the URL to be constructed with this variable price, so far we have this:

Any advice gratefully received! Thanks, Adrian.

<input type=hidden name="recipients" value="myemailaddress">
<input type=hidden name="subject" value="payment form">
<input type=hidden name="good_url" value="https://select-test.worldpay.com/wcc/purchase?instId=000000&cartId=WorldPay+Test&amount=40&currency=GBP&desc=WorldPay+Test&testMode=100">

Open in new window

anelson2008Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MMDeveloperCommented:
how is the value for good_url written to that HTML element? There has to be some dynamic script that writes that URL.
0
tben2008Commented:
So you want it to take subject , recipients and good_url. Then redirect to a page using that information.
0
anelson2008Author Commented:

MMD - good_ul is for FormMail.php which is using the information to post us a mail, good_url is the redirect which it goes to after posting the results of the form to us

tben2008 - we basically need a hidden field with a variable number in (that we can change manually) that'll form the price so in English (!) something like:

hiddenbox with price in (VAR)

We need to change good_url to:

https://select-test.worldpay.com/wcc/purchase?instId=000000&cartId=WorldPay+Test&amount=**VAR**¤cy=GBP&desc=WorldPay+Test&testMode=100"

but don't know how - plus can't alliterate it very well either!! Sorry.

Adrian

0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Ray PaseurCommented:

<?php // RAY_hidden_to_URL.php
 
if (!empty($_POST)) {
	echo $_POST["good_url"] . '&recipients=' . $_POST["recipients"] . '&subject=' . $_POST["subject"];
	die();
}
?>
 
<html>
<form method="post">
<input type=hidden name="recipients" value="myemailaddress">
<input type=hidden name="subject" value="payment form">
<input type=hidden name="good_url" value="https://select-test.worldpay.com/wcc/purchase?instId=000000&cartId=WorldPay+Test&amount=40&currency=GBP&desc=WorldPay+Test&testMode=100">
<input type="submit" value="Click Here" />
</form>
</html>

Open in new window

0
tben2008Commented:
Let me get this right. You want it to send the information to you and redirect to the good_url. Or for them all to be send to you.
0
Ray PaseurCommented:
If you are satisfied that the script above is echoing the right URL, you can use this to redirect.

All the usual caveats apply about filtering client input before using it in your script!

Best regards, ~Ray
<?php // RAY_hidden_to_URL.php
 
if (!empty($_POST)) {
	$target_url = $_POST["good_url"] . '&recipients=' . $_POST["recipients"] . '&subject=' . $_POST["subject"];
	header("Location: $target_url");
	exit;
}
?>
 
<html>
<form method="post">
<input type=hidden name="recipients" value="myemailaddress">
<input type=hidden name="subject" value="payment form">
<input type=hidden name="good_url" value="https://select-test.worldpay.com/wcc/purchase?instId=000000&cartId=WorldPay+Test&amount=40&currency=GBP&desc=WorldPay+Test&testMode=100">
<input type="submit" value="Click Here" />
</form>
</html>

Open in new window

0
anelson2008Author Commented:
Thank you all very much for your comments and suggestions. In the end I had a "frying pan in face" moment and solved it with as follows.

Now more problems so no doubt will be posting again tomorrow! Thanks again.

Adrian
<?php
$str_1 = '<input type=hidden name="good_url" value="https://select-test.worldpay.com/wcc/purchase?instId=000000&cartId=WorldPay+Test&amount=';
$str_2 = 'XYZ'; //price
$str_3 = '&currency=GBP&desc=WorldPay+Test&testMode=100">'
?>
 
//then where required:
 
<?php
echo $str_1,$str_2,$str_3
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
Don't forget to urlencode if you are sending it over the www!

Cheers, ~Ray
0
Ray PaseurCommented:
Kind of surprised you are asking to close this without giving any points for help.  

Especially since your OP said "trying to make a simple payment form that takes a price from a hidden field" and our posts here showed you EXACTLY how to do that, but the solution you posted doesn't even have a <form> statement in it.  

Are you sure you understand how EE works??  Why should we help you with your next question?
0
anelson2008Author Commented:
Ray, thanks for your post. Obviously we don't know each other but I'm sure if we did you'd probably think I was a decent chap and no doubt I'd may think likewise. If I've misunderstood the concept of how this all works (it involves the internets, a series of tubes right?) I'm happy to put right whatever I've done wrong. As for what I ended up doing, well, it worked for me - kinda dumb question with an equally dumb solution, granted, but we're all allowed off-days! Let me know what I should do & sorry to anyone else I may have offended.
0
Ray PaseurCommented:
Have a look at these links - the HELP page is rather long and most of the EE community has never read it in its entirety, but it gives some good cultural background information.  The Experts here volunteer their service and knowledge in exchange for points (and occasionally T-shirts that we can wear to job interviews).

http://www.experts-exchange.com/help.jsp#hi403
http://www.experts-exchange.com/help.jsp#hi407

See what you think.  Best, ~Ray
0
Ray PaseurCommented:
Sometimes I just don't get it.

 Why should we help you with your next question?

~Ray
0
Ray PaseurCommented:
Hi, Lunchy.  Apologies to you and anelson2008 if I was sounding too critical.  

The whole close/award points process may look different to you than it does to us.  On this end, what we see is the author saying thanks for all your help and goodbye.  I asked why there were no points for help.  Then, later on, we see the same goodbye thing again.  For some reason, the OP comments on closing the question do not show up in the comment stream above.  Perhaps if it did, the dialog would be easier to understand on both sides.

I think this may have come in one of those weeks when there were a lot of folks closing out their posts after lengthy dialogs with "Nevermind, I found the answer."  It can be frustrating when you've spent a good bit of time trying to help someone.

Anyway, no hard feelings on my part, and sorry if I rankled anyone.  Back to work.  Best regards, ~Ray
0
anelson2008Author Commented:
Thanks for your messages, please can you help me close the question in the right way - according to the help page I need an "accept multiple solutions" button which I can't see!
0
Ray PaseurCommented:
Hey, anelson2008 - Best regards, for 2009, ~Ray
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.