PDA

View Full Version : Can JavaScript Be Combined With Php?


mydogisthebest
16th April 2010, 21:29
Hi,

Can JavaScript Be Combined With Php?

I have an Order Form that the user fills in and in turn emails me the details (simple) but what I would like is some coding to seamlesly redirect the user at the point of email submit to PayPal for payment.

My Order / Details Form is in JavaScript, I have a php code to perform the above action, but I guess it would need to be JavaScript really.

Any help or coding appreciated :)

dots and spots Jeff
16th April 2010, 22:13
Javascript is a 'Client' side, PHP 'Server' side : i.e. Javascript runs the computer you are using, whilst PHP runs on the 'server' the computer at the other end of the wire from where you are sat accessing the internet.

The two are often used to compliment each other as they both have pros and cons.

However, javascript can't send emails - although it can use the 'mailto' method to fire up a users email client - e.g. outlook which they can then fill in to send the email.

You would use a server side script - say PHP - to send the contents of a form to you (or anyone else) as an email. But you might use javascript to validate the form before it gets sent - this is not just to check that the user has correctly filled in their postcode etc., it is really important to ensure that form entries are validated before being sent to prevent the user 'injecting' anything nasty in code form in the email form.

Alas, though, javascript can be turned off/bypassed by the user, so you still need to validate the form on the server side (using, say PHP) before it gets sent.

In summary - you need to be using PHP to send your form, but you may use a bit of javascript along the way! A webpage can happily contain HTML, PHP and Javascript all on the same page.

HTH

Jeff

nickjohnston
16th April 2010, 22:15
Great explanation by Jeff above, nothing else to add!

mydogisthebest
16th April 2010, 22:25
Thanks dots and spots jeff,

I'll do some testing in the daylight hours!

sanjiv
16th April 2010, 22:55
You could do this.

If your form was located at contact.htm, you could get it to submit the form to mail.php and get mail.php to redirect to the PayPal payment page. You probably wouldn't use JavaScript for this. Maybe a META redirect or something.

mydogisthebest
17th April 2010, 19:18
You could do this.

If your form was located at contact.htm, you could get it to submit the form to mail.php and get mail.php to redirect to the PayPal payment page. You probably wouldn't use JavaScript for this. Maybe a META redirect or something.

Hmmm Could / Should Work :)

Cheers sanj.