Download Ajax form submit

Demo

Bookmark and Share

Download files

You can download the entire script from this Zip file.

Files included in package

  • form-submit.html = Main HTML file
  • js/form-submit.js = Main JS file
  • js/ajax.js = Ajax (Library from http://twilightuniverse.com/projects/sack)
  • form-submit.php = PHP file which parses submtted data and outputs them back to the screen.

Configuration

This is a standalone version of the form submit class available in the DHTML Suite. The DHTMLSuite.form class is used to send a form to the server via Ajax. This is an example of the Javascript code used to create a form object:

var formObj = new DHTMLSuite.form({
formRef:'myForm',
action:'includes/formSubmit.php',
responseEl:'formResponse'}
);

As you can see, properties are sent to the constructor in an associative array:

  • formRef - Reference to the form. It could be a direct reference or the name or id of the form.
  • method - How to post the form - Optional, default = "POST".
  • action - Relative path to the file where the form will be submitted.
  • responseEl - Reference to HTML element where response from the server will be inserted. It could be a direct reference or the id of the element
  • responseFile - Path to alternative response file. When defined, the content of this file will be inserted into responseEl, i.e. instead of the response from the "action" file.
  • callbackOnComplete - Name of callback function to execute when the form has been submitted. This function will receive the name of the form as only argument.

The method "submit" is used to submit the form. Example:

<INPUT type="button" value="Send" onclick="formObj.submit()">

File uploads

When the form contains one or more form elements, the form will be submitted to a dynamically created and hidden iframe. When the form is finished submitted, the content of this iframe will be inserted into the element defined as responseEl.

Comments

Post your comment

Don't have an avatar? Create one at Gravatar.com.

Confirmation code:

Go to cbolson.com


About/Contact | A good idea? | Submit a script | Privacy notice
© 2005 - 2024 dhtmlgoodies.com