Jump to content


Ajax Submit Problem [SOLVED]


5 replies to this topic

#1 Braunson

    Young Padawan

  • Members
  • Pip
  • 237 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 17 August 2007 - 09:39 PM

Okay heres my main page for my 'edit category' for my gallery.

<?php

if(isset($_POST["save_category"])) {

	// this is our variables being submitted
	$title = htmlspecialchars($_POST["title"]);
	$description = htmlspecialchars($_POST["description"]);
	$date_added = date("F j, Y");
	$id = $_POST["id"];

	$etable = "Edited category from the Gallery";
	$result = mysql_query("UPDATE `admin_details` SET lastedit = '$etable' WHERE username='$username'");

	 $result = "UPDATE `gallery_categorys` SET title = '$title', description = '$description' WHERE id = '$id'";
		mysql_query($result)or die(mysql_error());


	// success, settings updated, now to redirect or echo something.
	echo "<meta http-equiv=\"refresh\" content=\"3 url=$domain/admin/index.php\">";
	echo "	<h1>Category Successfully Edited</h1>
		<p>Your gallery category have been successfully edited, and you are now being redirected back to the administrative home.</p>
	 ";
} else {

?>	

			<a name="editcategory"></a>
			<h1>Edit Category</h1>						
		
			<p>Feel free to edit a gallery category. You can do so below using the form below.</p>

<table width="100%" border="0" cellpadding="0" cellspacing="3" align="left">
<!--- settings start -->
	<tr>
		<td width="45%"><strong>» Select Category</strong></td>
		<td width="50%">
		<form> 
			<select name="photos" onchange="showGalleryCategorys(this.value)" style="margin: 0px; width: 95%; padding: 3px; border: 1px solid #e6e6e6;" />
			<option value="">---- Select an Category ----</option>
<?php 

		  $query = mysql_query("SELECT * FROM `gallery_categorys` ORDER BY position ASC");
		ifempty($query);
		while($r = mysql_fetch_array($query)){

			$id = $r["id"];
			$title = $r["title"];

echo "					<option value =\"$id\">$title</option>
";
		}

?>
			</select>
			</form></p>
		</td>
	</tr>

<!--- settings end -->
</table>

<table width="100%" border="0" cellpadding="0" cellspacing="3" align="left">
	<form name="pform" method="post" action="<?=$domain;?>/admin/index.php?go=pages/gallery&do=edit_category">
<!--- settings start -->
			<div id="txtHint"></div>
<!--- settings end -->
	</form>
</table></p>


<?php
}
?>

Now I have it load forms to edit in txtHint area through edit_category_2 using javascript & the dropdown.
But when I go to submit it and save it, it dosn't submit, it dosnt do anything.
Any ideas people?

Edited by Braunson, 07 September 2007 - 07:59 AM.


#2 Braunson

    Young Padawan

  • Members
  • Pip
  • 237 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 17 August 2007 - 09:42 PM

Edit, I found out when it displays the form to edit. the html is messed up. the content inside div id="txtHint" is moved out of the table... like so below..

<div id="txtHint">
	
		<strong>» Title</strong>
		
		<input name="title" value="Indoor Pool" style="border: 1px solid rgb(230, 230, 230); margin: 0px; padding: 3px; width: 95%;" type="text">
		<input name="id" value="3" type="hidden">
		
	
	
		<strong><br>» Description</strong>
		
		<textarea name="description" style="border: 1px solid rgb(230, 230, 230); margin: 0px; padding: 3px; width: 95%;">This is the indoor pool area</textarea>
		
	

	
		
		<input name="save_category" value="Finish Editing Category »" style="border: 1px solid rgb(230, 230, 230); margin: 5px 0px; padding: 4px; width: 50%; font-weight: bold; text-transform: uppercase;" type="submit">

		
	
</div>
<!--- settings end -->
	<table align="left" border="0" cellpadding="0" cellspacing="3" width="100%">
	<form name="pform" method="post" action="http://site.com/admin/index.php?go=pages/gallery&amp;do=edit_category"></form>
<!--- settings start -->
			
</table>

Why would it be doing this :P

#3 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 18 August 2007 - 07:52 AM

Is it doing that when inserting with JavaScript?
Make sure you are using the innerHTML property if that is how you are inserting it.

#4 Braunson

    Young Padawan

  • Members
  • Pip
  • 237 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 19 August 2007 - 05:43 PM

Here's how im using it. I didn't create the code.

function showGalleryCategorys(str)
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 } 
var url="./pages/gallery/edit_category_2.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("txtHint").innerHTML=xmlHttp.responseText 
 } 
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

Edited by Braunson, 19 August 2007 - 05:44 PM.


#5 .CJ

    Young Padawan

  • Members
  • Pip
  • 114 posts
  • Gender:Male
  • Location:Leeds, UK

Posted 20 August 2007 - 07:27 AM

Have you considered using Prototype? It makes Ajax that so much more easier... for example, to use it for form submission, you'd do:

new Ajax.Updater('div', 'file.php', {parameters: Form.serialize()});

Then you would add some XHTML like so:

<div id="div"></div>

And the requested data will show up in the DIV.

More information at http://www.prototypejs.org.

#6 Braunson

    Young Padawan

  • Members
  • Pip
  • 237 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 06 September 2007 - 04:35 PM

No thanks, I've thought of that. I'm trying to keep this script under a certain size. Anybody else know what's wrong with this code :o





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users