Create a Function from a button
Moderator: General Moderators
Create a Function from a button
Hello All
Thank you for allowing me to post to your forum.
I have a button that I need to turn into a function. here is the code that works for the button followed by the function code which is not setting the values for the button. Can anyone see what I may be doing wrong here? Thanks
Working Button:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value=<? renderSingleListingItemRaw($listingID, "email") ?>>
<input type="hidden" name="item_name" value=<? renderSingleListingItemRaw($listingID, "item_name") ?>>
<input type="hidden" name="amount" value=<? renderSingleListingItemRaw($listingID, "amount") ?>>
<input type="hidden" name="return" value="http://www.mysite.com">
<input type="hidden" name="notify_url" value="http://www.mysite.com">
<input type="image" src="https://www.paypal.com/images/x-click-but23.gif" name="submit">
</form>
Function code NOT working:
<?php
function renderpaypal() {
echo "<form action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\">\n";
echo "<input type=\"hidden\" name=\"cmd\" value=\"_xclick\" />\n";
echo "<input type=\"hidden\" name=\"business\" value=\"" . renderSingleListingItemRaw($listingID, "email") . "\" />\n";
echo "<input type=\"hidden\" name=\"item_name\" value=\"" . renderSingleListingItemRaw($listingID, "item_name") . "\" />\n";
echo "<input type=\"hidden\" name=\"amount\" value=\"" . renderSingleListingItemRaw($listingID, "amount") . "\" />\n";
echo "<input type=\"hidden\" name=\"return\" value=\"http://www.mysite.com\" />\n";
echo "<input type=\"hidden\" name=\"notify_url\" value=\"http://www.mysite.com\" />\n";
echo "<input type=\"image\" src=\"https://www.paypal.com/images/x-click-but23.gif\" name=\"submit\" />\n";
echo "</form>\n";
}
?>
Any insight would be GREAT! Thanks.
NYColt
Thank you for allowing me to post to your forum.
I have a button that I need to turn into a function. here is the code that works for the button followed by the function code which is not setting the values for the button. Can anyone see what I may be doing wrong here? Thanks
Working Button:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value=<? renderSingleListingItemRaw($listingID, "email") ?>>
<input type="hidden" name="item_name" value=<? renderSingleListingItemRaw($listingID, "item_name") ?>>
<input type="hidden" name="amount" value=<? renderSingleListingItemRaw($listingID, "amount") ?>>
<input type="hidden" name="return" value="http://www.mysite.com">
<input type="hidden" name="notify_url" value="http://www.mysite.com">
<input type="image" src="https://www.paypal.com/images/x-click-but23.gif" name="submit">
</form>
Function code NOT working:
<?php
function renderpaypal() {
echo "<form action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\">\n";
echo "<input type=\"hidden\" name=\"cmd\" value=\"_xclick\" />\n";
echo "<input type=\"hidden\" name=\"business\" value=\"" . renderSingleListingItemRaw($listingID, "email") . "\" />\n";
echo "<input type=\"hidden\" name=\"item_name\" value=\"" . renderSingleListingItemRaw($listingID, "item_name") . "\" />\n";
echo "<input type=\"hidden\" name=\"amount\" value=\"" . renderSingleListingItemRaw($listingID, "amount") . "\" />\n";
echo "<input type=\"hidden\" name=\"return\" value=\"http://www.mysite.com\" />\n";
echo "<input type=\"hidden\" name=\"notify_url\" value=\"http://www.mysite.com\" />\n";
echo "<input type=\"image\" src=\"https://www.paypal.com/images/x-click-but23.gif\" name=\"submit\" />\n";
echo "</form>\n";
}
?>
Any insight would be GREAT! Thanks.
NYColt
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
if you do this:
does it print anything? if so, then it's doing an echo/print.
look into it's code, if you have it, and possibly switch it to returning the final string instead of echo/print..
Code: Select all
<?php
renderSingleListingItemRaw("test","email");
?>look into it's code, if you have it, and possibly switch it to returning the final string instead of echo/print..
You see the first bit of code for the button sets the value. This works:
<input type="hidden" name="business" value=<? renderSingleListingItemRaw($listingID, "email") ?>>
What does NOT work is when I tried to do the same thing with the button but call it as a function. This does not work:
echo "<input type=\"hidden\" name=\"business\" value=\"" . renderSingleListingItemRaw($listingID, "email") . "\" />\n";
You see what I mean?
NYColt
<input type="hidden" name="business" value=<? renderSingleListingItemRaw($listingID, "email") ?>>
What does NOT work is when I tried to do the same thing with the button but call it as a function. This does not work:
echo "<input type=\"hidden\" name=\"business\" value=\"" . renderSingleListingItemRaw($listingID, "email") . "\" />\n";
You see what I mean?
NYColt
are you calling the function aswell ?
Code: Select all
//function
renderpaypal();you should look at youre browser for that, think you have seen the answer alreadyNYcolt wrote:Called it like this: <?php renderpaypal() ?> should work right?
however..
Code: Select all
// here is a function
<?php
function foo()
{
function bar()
{
echo "I don't exist until foo() is called.\n";
}
}
// calling the functions
foo();
bar();
?>That would mean youre code should be something like this
Code: Select all
<?php
function renderpaypal() {
echo "<form action="https://www.paypal.com/cgi-bin/webscr" method="post">\n";
echo "<input type="hidden" name="cmd" value="_xclick" />\n";
echo "<input type="hidden" name="business" value="" . renderSingleListingItemRaw($listingID, "email") . "" />\n";
echo "<input type="hidden" name="item_name" value="" . renderSingleListingItemRaw($listingID, "item_name") . "" />\n";
echo "<input type="hidden" name="amount" value="" . renderSingleListingItemRaw($listingID, "amount") . "" />\n";
echo "<input type="hidden" name="return" value="http://www.mysite.com" />\n";
echo "<input type="hidden" name="notify_url" value="http://www.mysite.com" />\n";
echo "<input type="image" src="https://www.paypal.com/images/x-click-but23.gif" name="submit" />\n";
echo "</form>\n";
}
renderpaypal(); // Now we are calling it ..
?>Thanks,
Calling the function is NOT the problem that is working fine.
The problem is in the button itself.
Before I converted the button to a function the button worked fine.
Button values set when I put the button directly on the page with this code:
<input type="hidden" name="business" value=<? renderSingleListingItemRaw($listingID, "email") ?>> <----this works. This sets the email address for pay pal, price Item ID everything.
When I turned it into a function I messed something up here:
echo "<input type=\"hidden\" name=\"business\" value=\"" . renderSingleListingItemRaw($listingID, "email") . "\" />\n"; <---this does NOT work I have the translation wrong.
See what I mean?
Something in the php syntax on the second bit of code is not right. It does not do the same thing the the first bit of code does.
Thanks
Calling the function is NOT the problem that is working fine.
The problem is in the button itself.
Before I converted the button to a function the button worked fine.
Button values set when I put the button directly on the page with this code:
<input type="hidden" name="business" value=<? renderSingleListingItemRaw($listingID, "email") ?>> <----this works. This sets the email address for pay pal, price Item ID everything.
When I turned it into a function I messed something up here:
echo "<input type=\"hidden\" name=\"business\" value=\"" . renderSingleListingItemRaw($listingID, "email") . "\" />\n"; <---this does NOT work I have the translation wrong.
See what I mean?
Something in the php syntax on the second bit of code is not right. It does not do the same thing the the first bit of code does.
Thanks
i wouldnt know how to help you on that part since most of youre code is using
other functions, that code is not availeble here..
Now that looks to me like a function
other functions, that code is not availeble here..
Code: Select all
renderSingleListingItemRaw($listingID, "email")- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Hang on, just noticed this. If I'm not mistaken, unless you have register globals on, $listingID will not be set once you are in the function. Try replacing this:with:
Code: Select all
function renderpaypal() {Code: Select all
function renderpaypal() {
$listingID = $GLOBALS['listingID'];