PDA

View Full Version : Problem with submitting forms using the DHTML Window Widget



parucleo
12-04-2008, 05:05 PM
Script: DHTML Window widget (v1.1)
http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/

Hey,

I'm trying to customise DHTML Window Widget version 1.1's Ajax DIV feature (as in the example: Window 3) to include html forms. This form would update/insert into my database. Finally the another the div would show a message confirming the submission.

The script goes as follows:
-------------------------------------------------------------------

<script type="text/javascript">
function openmypage(){
ajaxwin=dhtmlwindow.open("ajaxbox", "ajax", windowfiles/suggest_category.php", "Suggest a category for BMKP.org", "width=350px,height=200px,left=300px,top=100px,resize=1,scrolling=1")
ajaxwin.onclose=function(){return true;}
}
</script>

<p>
Want to <a href="#" onClick="openmypage(); return false">suggest a category</a>
</p>
-------------------------------------------------------------------
Naturally, this script opens up a dhtml window on the web page. The script (suggest_category.php) for this window looks like this:

-------------------------------------------------------------------
<div align="center">
<form id="myform" onsubmit="ajaxwin.load('ajax', 'windowfiles/submit_category.php', 'Suggest a category for BMKP'); return false" method="GET" action="">
<table cellpadding="" cellspacing="3">
<tr>
<td align="left">Your name*: </td>
<td align="left"><input type="text" name="name" /></td>
</tr>
<tr>
<td align="left">Email Address*: </td>
<td align="left"><input type="text" name="email" /></td>
</tr>
<tr>
<td align="left">A category you think should be added*: </td>
<td align="left"><input type="text" name="cat" /></td>
</tr>
<tr>
<td align="left">Cite a reason: </td>
<td align="left"><textarea name="reason" rows="" cols="15"></textarea></td>
</tr>
<tr>
<td align="left"></td>
<td align="center"><input type="submit" value="Suggest" /></td>
</tr>
</table>
</form>
</div>
-------------------------------------------------------------------
Now, this div does open up the page as the form attribute requires (submit_category.php) where upon receiving all the necessary form fields inserts the data into the mySQL database. But the problem is i can't make the form (above) to submit the name-value pairs to the next window (submit_category.php). The script for submit_category.php looks like this:

-------------------------------------------------------------------
<?php
if(!isset($_GET['name'],$_GET['email'],$_GET['cat']))
{
?>
<div align="center">
You did not provide any information for one/more field(s). Please go
<a href="#" onClick="ajaxwin.load('ajax', 'windowfiles/suggest_category.php', 'Suggest a category for BMKP.org'); return false">back</a>
and fill in all the required field(s).
</div>
<?php
}
else
{
$name=$_GET['name'];
$email=$_GET['email'];
$cat=$_GET['cat'];
$reason=$_GET['reason'];

include '../db/parameters.php';
include '../db/open.php';

$sql = "INSERT INTO suggest_category (
author,
category_name,
reason,
email,
status
)
VALUES (
'$name', '$cat', '$reason', '$email', 'c'
)";
mysql_query($sql,$conn) or die(mysql_error());

include '../db/close.php';


?>
<div align="center">
Thank you for your suggestion! You may now click the [X] key to exit this window.
</div>
<?php
}
?>
-------------------------------------------------------------------
Can someone kindly help me out? Thanks in advance.:)

ddadmin
12-05-2008, 06:29 AM
Please try and format any code in your post using the CODE tags. It just makes it easier to read.

An easier way may be to set the DHTML window to IFRAME mode, and have the form results submitted directly inside the IFRAME of that DHTML window. The results to show would simply be what your form.php script returns.

See this thread for info on how to change the target of a FORM so it points to a DHTML window with IFRAME mode: http://www.dynamicdrive.com/forums/showthread.php?t=19083

parucleo
01-18-2009, 12:06 PM
thanks a lot. think i might just have found the solution!