?
Solved

How to insert PHP variable into URL?

Posted on 2008-11-17
16
Medium Priority
?
1,296 Views
Last Modified: 2013-12-13
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

0
Comment
Question by:anelson2008
  • 8
  • 4
  • 2
  • +1
15 Comments
 
LVL 15

Expert Comment

by:MMDeveloper
ID: 22976185
how is the value for good_url written to that HTML element? There has to be some dynamic script that writes that URL.
0
 

Expert Comment

by:tben2008
ID: 22976219
So you want it to take subject , recipients and good_url. Then redirect to a page using that information.
0
 

Author Comment

by:anelson2008
ID: 22976278

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 111

Expert Comment

by:Ray Paseur
ID: 22976282

<?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
 

Expert Comment

by:tben2008
ID: 22976976
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
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 2000 total points
ID: 22977040
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
 

Accepted Solution

by:
anelson2008 earned 0 total points
ID: 22988606
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
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 22988621
Don't forget to urlencode if you are sending it over the www!

Cheers, ~Ray
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 22988791
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
 

Author Comment

by:anelson2008
ID: 22989643
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
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 22993912
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
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23025501
Sometimes I just don't get it.

 Why should we help you with your next question?

~Ray
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23051205
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
 

Author Comment

by:anelson2008
ID: 23077337
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
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23398199
Hey, anelson2008 - Best regards, for 2009, ~Ray
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question