JianTing
01-28-2011, 02:50 PM
1) Script Title: Dynamic Ajax Content
2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm
3) Describe problem:
Whenever i want to submit a form, it wont get submitted and redirects me to the homepage instead. Please help me. The code is(form):
<?php
require_once( "../commandcenter/_inc/glob.php" );
?>
<div id="maincont">
<div id="mainconttop"></div>
<div id="maincontmid">
<div id="contheadpink">Request Line</div>
<?php
if( $_POST['submit'] ) {
try {
$habbo = $core->clean( $_POST['habbo'] );
$type = $core->clean( $_POST['type'] );
$dj = $core->clean( $_POST['dj'] );
$request = $core->clean( $_POST['request'] );
$ip = $_SERVER['REMOTE_ADDR'];
$time = time();
if( !$habbo or !$type or !$dj or !$request or !is_numeric( $dj ) or !is_numeric( $type ) ) {
throw new Exception( "All fields are required" );
}
else {
$db->query( "INSERT INTO requests VALUES (NULL, '{$type}', '{$dj}', '{$habbo}', '{$request}', '{$time}', '{$ip}');" );
echo "<div class=\"good\">";
echo "<strong>Success</strong>";
echo "<br />";
echo "Request sent!";
echo "</div>";
}
}
catch( Exception $e ) {
echo "<div class=\"bad\">";
echo "<strong>Error</strong>";
echo "<br />";
echo $e->getMessage();
echo "</div>";
}
}
?>
<form action="" method="post" id="ajaxmenu">
<label for="habbo">Habbo name:</label>
<input type="text" name="habbo" id="habbo" maxlength="255" />
<br /><br />
<label for="type">Message type:</label>
<select name="type" id="type">
<?php
$query = $db->query( "SELECT * FROM request_types" );
while( $array = $db->assoc( $query ) ) {
?>
<option value="<?php echo $array['id']; ?>">
<?php echo $array['name']; ?>
</option>
<?php
}
?>
</select>
<br /><br />
<label for="dj">DJ:</label>
<select name="dj" id="dj">
<?php
$query2 = $db->query( "SELECT * FROM users" );
while( $array2 = $db->assoc( $query2 ) ) {
?>
<option<?php if( preg_match( "/{$array2['username']}/", $info['streamtitle'] ) ) { ?> selected="selected"<?php } ?> value="<?php echo $array2['id']; ?>">
DJ <?php echo $array2['username']; ?>
</option>
<?php
}
?>
</select>
<br /><br />
<label for="request">Request:</label>
<textarea name="request" id="request" rows="5"></textarea>
<br /><br />
<input onClick="ajaxcombo('ajaxmenu', 'sitecont')" class="button" type="button" name="submit" value="Request" />
</form>
</div>
<div id="maincontbot"></div>
</div>
2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm
3) Describe problem:
Whenever i want to submit a form, it wont get submitted and redirects me to the homepage instead. Please help me. The code is(form):
<?php
require_once( "../commandcenter/_inc/glob.php" );
?>
<div id="maincont">
<div id="mainconttop"></div>
<div id="maincontmid">
<div id="contheadpink">Request Line</div>
<?php
if( $_POST['submit'] ) {
try {
$habbo = $core->clean( $_POST['habbo'] );
$type = $core->clean( $_POST['type'] );
$dj = $core->clean( $_POST['dj'] );
$request = $core->clean( $_POST['request'] );
$ip = $_SERVER['REMOTE_ADDR'];
$time = time();
if( !$habbo or !$type or !$dj or !$request or !is_numeric( $dj ) or !is_numeric( $type ) ) {
throw new Exception( "All fields are required" );
}
else {
$db->query( "INSERT INTO requests VALUES (NULL, '{$type}', '{$dj}', '{$habbo}', '{$request}', '{$time}', '{$ip}');" );
echo "<div class=\"good\">";
echo "<strong>Success</strong>";
echo "<br />";
echo "Request sent!";
echo "</div>";
}
}
catch( Exception $e ) {
echo "<div class=\"bad\">";
echo "<strong>Error</strong>";
echo "<br />";
echo $e->getMessage();
echo "</div>";
}
}
?>
<form action="" method="post" id="ajaxmenu">
<label for="habbo">Habbo name:</label>
<input type="text" name="habbo" id="habbo" maxlength="255" />
<br /><br />
<label for="type">Message type:</label>
<select name="type" id="type">
<?php
$query = $db->query( "SELECT * FROM request_types" );
while( $array = $db->assoc( $query ) ) {
?>
<option value="<?php echo $array['id']; ?>">
<?php echo $array['name']; ?>
</option>
<?php
}
?>
</select>
<br /><br />
<label for="dj">DJ:</label>
<select name="dj" id="dj">
<?php
$query2 = $db->query( "SELECT * FROM users" );
while( $array2 = $db->assoc( $query2 ) ) {
?>
<option<?php if( preg_match( "/{$array2['username']}/", $info['streamtitle'] ) ) { ?> selected="selected"<?php } ?> value="<?php echo $array2['id']; ?>">
DJ <?php echo $array2['username']; ?>
</option>
<?php
}
?>
</select>
<br /><br />
<label for="request">Request:</label>
<textarea name="request" id="request" rows="5"></textarea>
<br /><br />
<input onClick="ajaxcombo('ajaxmenu', 'sitecont')" class="button" type="button" name="submit" value="Request" />
</form>
</div>
<div id="maincontbot"></div>
</div>