4

I want to ask people to donate to my website. Right now, I have a big, friendly "Donate via PayPal" button on my site, and when someone clicks on it, it takes them to PayPal, and they can enter the amount they want to donate and whatnot.

Is there any way I can just get them directly to the PayPal page, without having to click the "Donate" button on my website?

Ideally, I want to be able to tell people "just go to mywebsite.com/donate" and when they type that web address in their browser (or click a link to that URL), they get taken directly to the PayPal page where they can enter all their payment details and such.

4

On your mywebsite.com/donate page, you will need to construct a form and then automatically submit it using JavaScript. A basic example:

<form id="my_form" action="http://paypal.com" method="post">
    <input type="hidden" name="name" value="Example">
    <input type="hidden" name="email" value="test@test.com">
    <input type="hidden" name="etc" value="etc, etc">
</form>

<script type="text/javascript">
    //Our form submission function.
    function submitForm() {
        document.getElementById('my_form').submit();
    }
    //Call the function submitForm() as soon as the page has loaded.
    window.onload = submitForm;
</script>

Obviously, you will need to provide the form variables that PayPal requires.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.