I'm new to HTML and JavaScript, and am trying to build a personal website, or more specifically, one with a contact page. If I wanted to have a "comment" type box, whereby I type the text into a box, push a button, and have the text sent to my email address? I have seen things similar to this in other websites, but I'm not sure if they have the text sent to an email like I want to do. Would anyone be able to help?
I'm new to HTML and JavaScript, and am trying to build a personal website, or more specifically, one with a contact page.
If you are new to something, you should be spending more of your time trying to learn it than do it. Programming is not something that you can jump into and think everything is just going to work.
If you are looking to handle it as a form, then you need to have something like a PHP server with the correct PHP code on it to handle the form input and possibly do the SMTP (mail) transaction.
And please, if you expect to receive any help, at least make an attempt to try. Post some code.
It's an AJAX form that sends the email without refreshing the page. If you want to do it this way, read up how to make and handle an AJAX request (I used jQuery: http://api.jquery.com/jQuery.ajax/) to send the form data to a php script on the server. Then with php I used the mail() function to send the message: http://php.net/manual/en/function.mail.php
Big O, How do I tie the jQuery and PHP scripts together? The jQuery has examples of it's text, and likewise with the PHP, but there are no examples of how they are tied together?
Big O, How do I tie the jQuery and PHP scripts together? The jQuery has examples of it's text, and likewise with the PHP, but there are no examples of how they are tied together?
- jQuery is JavaScript (Client-Side)
- PHP is .. PHP (Server-Side)
There are two computers here. The "Server", and the "Client". The "Server" reads the PHP, and from that it gets the necessary JavaScript/HTML and sends that to the client. The "Client" reads HTML/JavaScript and from that you get what you are looking at right now...
Thanks for replying, it helped a lot. However, what I was trying to ask is this;
If one is to create a comment/message box, they would have to do it with HTML/JavaScript. However, to have the message box become functional, and send it's content to a specific location, i.e., an email address, the need PHP (from what I'm aware of)
Earlier on the posts, Big O sent: "I used jQuery...to send the form data to a php script on the server"
I'm not sure if I'm succeeding in asking my question how I'm thinking it. When a person wants to add CSS to a script they type "<script type="text/css">" if they want to add JavaScript, they say, "<script type="text/javascript">"...so they can "tie" the two scripts onto the one page. How would one do this with PHP? Type, "<script type="text/php">"?
Thanks for replying, it helped a lot. However, what I was trying to ask is this;
If one is to create a comment/message box, they would have to do it with HTML/JavaScript. However, to have the message box become functional, and send it's content to a specific location, i.e., an email address, the need PHP (from what I'm aware of)
Earlier on the posts, Big O sent: "I used jQuery...to send the form data to a php script on the server"
I'm not sure if I'm succeeding in asking my question how I'm thinking it. When a person wants to add CSS to a script they type "<script type="text/css">" if they want to add JavaScript, they say, "<script type="text/javascript">"...so they can "tie" the two scripts onto the one page. How would one do this with PHP? Type, "<script type="text/php">"?
The following is invalid. CSS is not a type of "script"
Code:
<script type="text/css">
And as I said earlier, PHP is done on the server-side. PHP is a language used to generate the HTML/CSS/JavaScript that the browser uses.
This is a PHP example to generate a simple string used in HTML:
PHP Code:
<?php echo "HTML OUTPUT" ?>
You *NEED* to put the file on a PHP server, even just to test the PHP. I think instead of asking questions here you should probably be looking at basic PHP tutorials. Make sure you read the information about PHP form handling, but try not to skip anything...
To answer your question, PHP is "tied" into HTML with <?php ... ?>:
PHP Code:
<!doctype html> <html> <head> <title>simple php example</title> </head> <body> <?php // Here's where you put your PHP script for($i = 1; $i <= 10; $i++) { echo($i + ' '); } ?> </body> </html>
However, as Gray is saying, if save this as a .html file and try to open it in a web browser it won't execute the PHP part because the browser doesn't have a PHP interpreter. This is something you would upload to a PHP server (as a .php file) and then retrieve from the server. The server preprocesses the PHP scripts and returns an HTML file.
If you don't have a PHP server then I would take this suggestion to handle your current situation:
Originally Posted by rnd me
just make a new google form and paste the embed code into your website.
And by all means learn about PHP! If you want to learn, you can get a PHP server on your computer. If you're a Windows user, look up XAMPP for information on installing a PHP server on your own computer. Or if you have Windows Professional or Home Premium you can use IIS. But actually getting a PHP script to do what you want is a ways off if you've never set up a server before.
Last edited by nathanwall; 04-13-2012 at 01:30 PM.
And by all means learn about PHP! If you want to learn, you can get a PHP server on your computer. If you're a Windows user, look up XAMPP for information on installing a PHP server on your own computer. Or if you have Windows Professional or Home Premium you can use IIS. But actually getting a PHP script to do what you want is a ways off if you've never set up a server before.
Bookmarks