SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How i can submit this form in ajax




    Hi all

    I want when i press save button a result appeard in the div element id"result"

    Please help me to do that

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" dir="rtl">
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
    <meta http-equiv="Content-Language" content="ar-eg" />
    <title>add_thread</title>
    <link rel="stylesheet" type="text/css" href="css/admin.css" />
    </head>
    
    <body>
    <form name="myform" action="add_new.php" method="get">
    <table style="width: 100&#37;" class="maintableborder1">
    	<tr>
    		<td style="height: 475px"><span class="normalfont"><span lang="ar-sa">add new thread<br />
    		</span></span><span lang="ar-sa" class="cells">
    		<hr /></span><span lang="ar-sa">
    
    			<div>
    				<span class="normalfont">thread title</span></div>
    			<span lang="ar-sa" class="cells"><br />
    			</span>
    			<span class="style2">
    			<span lang="ar-sa" class="cells">
    			<input name="address" id="ad1" type="text" class="normalfont" /><br />
    			</span>
    			</span><span lang="ar-sa"><br />
    			<div class="normalfont" style="width: 233px">
    				<span class="cells">body </span></div>
    				<br/>
    			<textarea name="subject" id="ad2" style="height: 198px; width: 459px" class="options" dir="rtl"></textarea><br />
    			</span><span lang="en-us"></span><span lang="ar-sa"><br />
    			<input name="Submit1" type="submit"  value="save" class="normalfont" />&nbsp;&nbsp;<input name="Reset1" type="reset" value="resr" class="normalfont" /></td>
    	</tr>
    </table>
    </form>
    <br/><br />
    <br/>
    <hr/>
    <div id="result"></div>
    <hr/>
    
    </body>
    
    </html>

    and this is the phpcode

    PHP Code:
    <?php
    require_once  '../include/setting.php' ;
    //##################################
    $datetime=date("d/m/y h:i:s"); 
    $query "INSERT INTO news (address,subject) VALUES ('$address','$subject') ";
    $result mysql_query($query);
    if (
    $result)
    {
        echo 
    " thread added succesfully ";
        echo 
    "<br>";
        echo 
    "Press here to return back";
     }
     else
     {
     echo 
    " Error ";
     }

    print_r($_POST);


     
    ?>

    Regards

  2. #2
    Working on it... Contrid's Avatar
    Join Date
    Apr 2006
    Location
    Online
    Posts
    955
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It's quite a task and will consist of a large amount of explaining.

    First off...
    I'd suggest that you look at the jQuery library. It's lightweight and provides you with a set of amazingly powerful tools. Creating Ajax forms with jQuery is a breeze.

    The way I do the PHP side of Ajax in most cases is to send an XML structured data response. It works best for me most of the time. When you do decide to do an XML response, remember to set the content-type header before outputting the XML data. Like this :

    Code php:
    header("Content-type: text/xml");

    From there, once you have your response with the values you need, you can update a specific element using jQuery selectors. Right now, I cannot give you an example, since I work with Prototype (they might be similar in a way though) and don't want to mislead you.
    And so I got lost in code...completely asphyxiated by it...

    Premium WordPress plugins - Tribulant Software

  3. #3
    Working on it... Contrid's Avatar
    Join Date
    Apr 2006
    Location
    Online
    Posts
    955
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Go to this page :
    http://docs.jquery.com/Tutorials

    ...and scroll down to the Ajax section.
    You'll find some easy to follow tutorials there.
    And so I got lost in code...completely asphyxiated by it...

    Premium WordPress plugins - Tribulant Software


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •