Page 1 of 1

No forms on server will submit

Posted: Mon Jan 05, 2009 4:29 pm
by CoolAsCarlito
Can someone tell me exactly though how to fix my code for my ajax.

So I figured out whats going on here its a conflict between my AJAX and my form submissions, I see the issue I'm having is that I'm using AJAX when I shouldn't be using AJAX.

Its a bit hard to explain but simply put my ajax is calling the newhandler() function when a user can click the handlers link in the sidebar and when they click the new handler button at the top.

Up until this point everything works fine and I could almost leave it like that but this is where the issue comes into play, it loads up your form just fine but now when the user clicks the submit button on my form the function newhandler() no longer gets called because my AJAX file is the only one which can call it at this point.

Code: Select all

 
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
 
function ajaxpage(url, containerid)
{
   url = 'backstagefunctions.php?f=' + url;
 
   var page_request = false
   if (window.XMLHttpRequest) // if Mozilla, Safari etc
   page_request = new XMLHttpRequest()
   else if (window.ActiveXObject)
   {
      // if IE
      try
      {
         page_request = new ActiveXObject("Msxml2.XMLHTTP")
      }
      catch (e)
      {
         try
         {
            page_request = new ActiveXObject("Microsoft.XMLHTTP")
         }
         catch (e)
         {
         }
      }
   }
   else
   {
      return false
   }
 
   page_request.onreadystatechange=function()
   {
      loadpage(page_request, containerid)
   }
 
   page_request.open('GET', url, true)
   page_request.send(null)
}
 
function loadpage(page_request, containerid)
{
   if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
   document.getElementById(containerid).innerHTML=page_request.responseText
}
 
function loadobjs()
{
   if (!document.getElementById)
   return
   for (i=0; i<arguments.length; i++)
   {
      var file=arguments[i]
      var fileref=""
      if (loadedobjects.indexOf(file)==-1)
      {
         //Check to see if this object has not already been added to page before proceeding
         if (file.indexOf(".js")!=-1)
         {
            //If object is a js file
            fileref=document.createElement('script')
            fileref.setAttribute("type","text/javascript");
            fileref.setAttribute("src", file);
         }
         else if (file.indexOf(".css")!=-1)
         {
            //If object is a css file
            fileref=document.createElement("link")
            fileref.setAttribute("rel", "stylesheet");
            fileref.setAttribute("type", "text/css");
            fileref.setAttribute("href", file);
         }
      }
      if (fileref!="")
      {
         document.getElementsByTagName("head").item(0).appendChild(fileref)
         loadedobjects+=file+" " //Remember this object as being already added to page
      }
   }
}
 
function WrestlerList()
{
var addWrestler = document.addwrestler.characterid.value;
if (addWrestler) {
document.getElementById("characterlist").innerHTML += "<li>" + addWrestler + "</li>";
return WrestlerList;
}
else {
document.getElementById("characterlist").innerHTML += "<li>This handler does not have any characters assigned.</li>";
}
}
 

Re: No forms on server will submit

Posted: Mon Jan 05, 2009 6:38 pm
by it2051229
I can't see the button or the script that creates the submit button. make sure the button has an onclick attribute pointing to "newhandler()" and I prefer using button than submit button if using ajax request.

The way I see it looks like the "form" (html form tag and other tags inside it) is from the Server and is being requested via ajax. I tried this before but the only difference is that I am requesting a table (table tag) and inside the table tags has buttons with events (onclick). But the problem I had is that the events did not work when it was requested from server and rendered on the browser which I assume is your problem also. What I did was just to request the data of the table BUT the creation of the table structure and events, I did it on the javascript side using Javascript DOM or the "innerHTML (easier)".

Re: No forms on server will submit

Posted: Mon Jan 05, 2009 6:45 pm
by CoolAsCarlito

Code: Select all

function newhandler() {
    if (isset ( $_POST ['submit2'] )) { // Handle the form.
        // Define the query.
        $password = md5($p); // Currently $p does not have a value
        $login = $_POST['login'];
        $p = $_POST['password'];
        $surname = $_POST['surname'];
        $firstname = $_POST['firstname'];
        $email = $_POST['email'];
        $aim = $_POST['aim'];
        $msn = $_POST['msn'];
        $forumid = $_POST['forumid'];
        $account = $_POST['account'];
        $admin = $_POST['admin'];
        
        // This query should now work
        $query = "INSERT INTO users (username, password, surname, firstname, email, aim, msn, forumid, status, admin) VALUES ('".addslashes($login)."', '".addslashes($p).", '".addslashes($surname).",'".addslashes($firstname).", '".addslashes($email).", '".addslashes($aim).", '".addslashes($msn).", '".addslashes($forumid).", '".addslashes($account).", '".addslashes($admin)."')";
        
        // Execute the query.
        if (@mysql_query ( $query )) {
            print '<p>The handler has been added.</p>';
        } else {
            print '<p>Could not add the entry because: <b>"' . mysql_error() . '"</b>. The query was '.$query.'.</p>';
        }
        mysql_close ();
    
    }
    
    print '<h1 class="backstage">Handler Management</h1><br />';
    print '<h2 class="backstage">Add New Handler Account</h2><br />';
    print '<form name="newhandler" method="post">';
    print '<table width="100%" class="table2">';
    print '<tr>';
    print '<td width="120" class="rowheading">Username:</td><td class="row3"><input type="text" name="login" class="fieldtext490"></td>';
    print '</tr>';
    print '<tr>';
    print '<td class="rowheading">Password:</td><td class="row3"><input type="password" name="password" class="fieldtext490"></td>';
    print '</tr>';
    print '<tr>';
    print '<td class="rowheading">Surname:</td><td class="row3">';
    print '<input type="text" name="surname" class="fieldtext490"></td>';
    print '</tr>';
    print '<tr>';
    print '<td class="rowheading">Firstname:</td>';
    print '<td class="row3"><input type="text" name="firstname" class="fieldtext490"></td>';
    print '</tr>';
    print '<tr>';
    print '<td class="rowheading">Email:</td>';
    print '<td class="row3"><input type="text" name="email" class="fieldtext490"></td>';
    print '</tr>';
    print '<tr>';
    print '<td class="rowheading">AIM:</td>';
    print '<td class="row3"><input type="text" name="aim" class="fieldtext490"></td>';
    print '</tr>';
    print '<tr>';
    print '<td class="rowheading">MSN:</td>';
    print '<td class="row3"><input type="text" name="msn" class="fieldtext490"></td>';
    print '</tr>';
    print '<tr>';
    print '<td class="rowheading">Forum ID:</td>';
    print '<td class="row3"><input type="text" name="forumid" class="fieldtext490"></td>';
    print '</tr>';
    print '<tr>';
    print '<td class="rowheading">Account:</td>';
    print '<td class="row3"><select name="account" class="selection">';
    print '<option value="Enabled">Enabled</option><option value="Disabled">Disabled</option>';
    print '</select></td>';
    print '</tr>';
    print '<tr>';
    print '<td class="rowheading">Administrator:</td>';
    print '<td class="row3"><select name="admin" class="selection">';
    print '<option value="2">No</option><option value="1">Yes</option>';
    print '</select></td>';
    print '</tr>';
    print '</table><br />';
    print '<input type="submit" value="Save Handler" class="button" name="submit2"></form><br />';
    print '<input type="hidden" name="action" value="handlers"><input type="submit" value="Return to Handler List" class="button200"><br />';
    print '<script type="text/javascript" src="ajax.js"></script>';
    print '<h2 class="backstage">Characters<br /><br />';
    print '<form method=post name="addwrestler" onsubmit="return WrestlerList(this);"><select name="characterid" class="dropdown">';
    print '<option value="">- Select -</option>';
    $query = 'SELECT charactername FROM characters';
    $result = mysql_query ( $query );
    while ( $row = mysql_fetch_assoc ( $result ) ) {
        print "<option value=\"".$row['charactername']."\">".$row['charactername']."</option>\r";
    }
    print '</select>&nbsp;&nbsp;<input name="submit" type="submit" value="Add" class="button"></form></h2><br />';
    print '<ul id="characterlist"></ul>';
    print 'This handler does not have any characters assigned.<br /><br />';
    print '<h2 class="backstage"><form method="post"><input type="submit" value="Return to Main Menu" class="button200"></form></h2>';
}
 
function edithandler() {
    print '<h1 class=backstage>Handler Management</h1><br />';
    print '<h2 class=backstage>Edit Handler Details</h2><br />';
    print '<table width="100%" class="table2">';
    print '<tr>';
    print '<td width=120 class=rowheading>Username:</td><td class=row3><input type=text name=login class=fieldtext490 value=""></td>';
    print '</tr>';
    print '<tr>';
    print '<td class=rowheading>Password:</td><td class=row3><input type=password name=password class=fieldtext490 onfocus="this.select()" value=""></td>';
    print '</tr>';
    print '<tr>';
    print '<td class=rowheadingred>Surname:</td><td class=row3>';
    print '<input type=text name=surname class=fieldtext490 value=""></td>';
    print '</tr>';
    print '<tr>';
    print '<td class=rowheading>Firstname:</td>';
    print '<td class=row3><input type=text name=firstname class=fieldtext490 value=""></td>';
    print '</tr>';
    print '<tr>';
    print '<td class=rowheading>Email:</td>';
    print '<td class=row3><input type=text name=email class=fieldtext490 value=""></td>';
    print '</tr>';
    print '<tr>';
    print '<td class=rowheading>AIM:</td>';
    print '<td class=row3><input type=text name=aim class=fieldtext490 value=""></td>';
    print '</tr>';
    print '<tr>';
    print '<td class=rowheading>MSN:</td>';
    print '<td class=row3><input type=text name=msn class=fieldtext490 value=""></td>';
    print '</tr>';
    print '<tr>';
    print '<td class=rowheading>Forum ID:</td>';
    print '<td class=row3><input type=text name=forumid class=fieldtext490 value=""></td>';
    print '</tr>';
    print '<tr>';
    print '<td class=rowheading>Account:</td>';
    print '<td class=row3><select name=enabled class=selection>';
    print '<option value=1>Enabled<option value=0>Disabled</option>';
    print '</select></td>';
    print '</tr>';
    print '<tr>';
    print '<td class=rowheading>Administrator:</td>';
    print '<td class=row3><select name=isadministrator class=selection>';
    print '<option value=1>Yes<option value=0>No';
    print '</select></td>';
    print '</tr>';
    print '<tr>';
    print '<td class=rowheading>Default Character:</td>';
    print '<td class=row3></td>';
    print '</tr>';
    print '</table><br />';
    print '<input type=checkbox name=deletehandler> <span class=table1heading>Delete Handler?</span><br /><br />';
    print '<input type=submit value="Save Handler" class=button></form><br />';
    print '<form method=POST><input type=hidden name=action value=handler><input type=submit value="Return to Handler List" class=button200></form><br />';
    print '<h2 class=backstage>Characters<br /><br /><form method=post><input type=hidden name=action value=handler><input type=hidden name=routine value=addcharacter><input type=hidden name=option value=0><input type=hidden name=id value="130"><select name=characterid class=dropdown>';
    print '<option value=0>- Select -</select>&nbsp;&nbsp;<input type=submit value="Add" class=button></form></h2><br />';
    print '<br /><br />';
    print '<h2 class=backstage><form method=POST><input type=hidden name=action value=mainmenu><input type=submit value="Return to Main Menu" class=button200></form></h2>';
}
 

Re: No forms on server will submit

Posted: Tue Jan 06, 2009 4:01 am
by it2051229
ok i thought newhandler is a javascript function that does the XML HTTP request.. now i'm confused with the flow of your code.