Jump to content

contact form


jimfog

Recommended Posts

Should I use ajax to submit the message sent from a simple contact form or not?

 

What is usually done with contact forms nowadays?

 

It is just a simple contact form where a user will be able to communicate with the site admins

Link to comment
Share on other sites

Ajax is all about receiving data from the server, not sending data to the server, right? When you "use Ajax to submit" you are really just setting up things to receive the response data from the server.

Link to comment
Share on other sites

HTTP is request/response, you send a request and get a response. The request can contain whatever data you want to send. I don't have any opinion on whether he wants to set up a contact form to use ajax, though. If you want the contact form to use ajax, then use ajax. If you don't, then don't.

Link to comment
Share on other sites

All depends on how much of the page needs to be updated. If it's part of the page, use AJAX, else use PHP. Here's the tut that got me started with AJAX: http://www.w3schools.com/php/php_ajax_intro.asp

Edited by niche
Link to comment
Share on other sites

I guess you have to use Ajax if you don't want to reload the page, even if you don't expect any response data. I don't think you can submit a form without an action and even if action is set to the current page it would then reload the current page.

Edited by davej
Link to comment
Share on other sites

Ajax would only reload the part of the page that you tell it to.

Link to comment
Share on other sites

Ajax would only reload the part of the page that you tell it to.

 

In this case he doesn't need anything loaded or reloaded, although I guess it might be nice to have a status message to tell the user the form passed the server validation and was accepted.

Link to comment
Share on other sites

I guess you have to use Ajax if you don't want to reload the page, even if you don't expect any response data. I don't think you can submit a form without an action and even if action is set to the current page it would then reload the current page.

You can override default behaviour of a form using JS. Form field will have the data , It is reponosibility of coder to collect the data and send it to server and block default bhevaiour of form. Other than that ajax is like reguler HTTP request, except it does it in background so it dont reload the page.

Link to comment
Share on other sites

 

 

although I guess it might be nice to have a status message to tell the user the form passed the server validation and was accepted.

 

Yes. This is good user interface. Users hate it if there's no confirmation.

Link to comment
Share on other sites

You can override default behaviour of a form using JS. Form field will have the data , It is reponosibility of coder to collect the data and send it to server and block default behaviour of form. Other than that ajax is like regular HTTP request, except it does it in background so it dont reload the page.

 

I guess what I'm confused about is whether the submission of a form truly forces a page load. What if the server accepts the form but does not send a response?

 

http://www.w3schools.com/tags/tag_form.asp

http://www.w3schools.com/tags/att_form_action.asp

 

--update--

 

Now I remember -- I was not working on AJAX. I was working on supporting Javascript being turned on or off. The first case was Javascript turned off. The second case was if Javascript was turned on but an AJAX object could not be obtained. The third case was if Javascript was on and AJAX was available.

 

Yes, if the form is submitted either directly or by Javascript it is going to reload the page.

Edited by davej
Link to comment
Share on other sites

All in all.it seems an ajax contact form with a status confirmation message will be OK

Link to comment
Share on other sites

I guess what I'm confused about is whether the submission of a form truly forces a page load. What if the server accepts the form but does not send a response?

 

Server will always response in regular HTTP response. Like HTTP code 200,404...etc. Whether a 200 response will have data or not (like confirmation message or any other data) is depend upon the developer. But no matter it returns data or not the HTTP request from ajax form would change the data in server already.

 

Ajax does not forces page load. In regular HTTP request browser parses the response to render it. so it get restructured (page load). Even a blank page will have HTPP response. Where as in AJAX browser does not parses the reponse to display it. instead it resides on a memory to be handled by developer. You can use any HTTP debugger to see the data going back and forth in server-client.

Edited by birbal
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...