Jump to content

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 post
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 post
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 post
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 post
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 post
Share on other sites

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

Link to post
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 post
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 post
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 post
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 post
Share on other sites

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

Link to post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...