PDA

View Full Version : Form action help please



SmileUK
30-01-2009, 04:22 PM
How come:

<form method='post' action='javascript:ajaxpage\(\'http://www.*****.com/staff/request.php?op=reg\'\,%20\'contentarea\'\)\;'>

doesn't work.

it's on a php page to make a form do what i've put there.
i take it i can't make a submit button do javascript?

or i've totally messed it up somewhere.

url blocked out btw.

Current full page:

<?

include "config.php";
include "front_page_stats.php";

?>

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Request Line</title>
<style type="text/css">
body {background-color: transparent}
</style>
<link href="../css/staff.css" rel="stylesheet" type="text/css" />

</head>

<body>

<div class="headn blue">Request &amp; Shoutout Line</div>
Want to send a message to a DJ? Well here is the place to do so. Whether you've come to enter a competition, ask for a song or just want to say something that's on your mind, this is the form <em>you</em> need to fill in.<br />
Your IP is: <? $ip=$_SERVER['REMOTE_ADDR']; echo "<strong>$ip</strong>"; ?>. This is sent with the request for security issues.<br />

<?

if($_GET["op"] == "reg") {

//$result = mysql_query("SELECT * FROM `staff`");

//while($worked = mysql_fetch_array($result)) {

//$get_word = $worked['username'];

//if(preg_match("/$get_word/i", "$servertitle")) { $dj_name = "$get_word"; }

//}

$dj_name = addslashes($_POST["dj_name"]);

if($dj_name == "Choose One...") { echo "<br /><br /><strong>You need to select a DJ or No one will receive your message!</strong>"; exit; }

$habboname = $_POST["habboname"];
$message = $_POST["message"];

if($habboname == "") { echo "<br /><br /><strong>Please fill in your Habbo name.</strong><br />"; exit; }

$habboname = addslashes($_POST["habboname"]);

$request = addslashes($_POST["request"]);

$type = addslashes($_POST["type"]);

$ip = getenv("REMOTE_ADDR");

$date = date("d.m.y - H:i:s");

$query = mysql_query("INSERT INTO `requests` (`habboname`, `type`, `dj_name`, `message`, `ip`, `date`) VALUES('$habboname', '$type', '$dj_name', '$request', '$ip', '$date' )");

echo "<br /><br /><strong>Thank you <em>$habboname</em> for your <em>$type</em> stay tuned your message may appear soon!<META HTTP-EQUIV='Refresh' CONTENT='2;URL=request.php";

} else { echo "

<form method=\"get\" action=\"#\" onsubmit=\"javascript:ajaxpage('http://eachhabbo.com/staff/request.php?op=reg', 'contentarea'); return false;\">

<br /><br />Habbo Name:<br />
<input type='text' name='habboname' size='30'></font><br /><br />

Type:<br />
<select name='type'>
<option value='Request'>Request</option>
<option value='Shoutout'>Shoutout</option>
<option value='Joke'>Joke</option>
<option value='Other'>Other</option>
<option value='Comp'>Competition</option>
</select><br /><br />

Select A DJ:<br />
<select name='dj_name'>";

$result = mysql_query("SELECT * FROM `staff`");

while($worked = mysql_fetch_array($result)) {

$get_word = $worked['username'];

if(preg_match("/$get_word/i", "$servertitle")) { echo "<option value='$get_word' selected>DJ $get_word</option>"; }

else { echo "<option value='$get_word'>DJ $get_word</option>"; }

}

echo "</select><br /><br />

Your Message:<br />
<textarea rows='3' cols='35' type='text' name='request' class='button'></textarea><br /><br />

<input type='submit' name='submit' value='Send Your Message'>";}

?>

</body>

</html>

Also tried (and a few variations of these):
<form method="get" action="#" onsubmit="ajaxpage('http://www.*****.com/staff/request.php?op=reg', 'contentarea'); return false;">
<form method="post" onsubmit="javascript:ajaxpage('http://www.*****.com/staff/request.php?op=reg', 'contentarea');">
<form method='post' onsubmit='javascript:ajaxpage\(\'http://www.*****.com/staff/request.php?op=reg\'\,%20\'contentarea\'\)\;'>

Iszak
30-01-2009, 04:35 PM
I suggest using unobtrusive javascript which means no inline javascript which allows you to manage it easier. If you want I could possible convert it to jQuery - I know this is not what you asked, but I think it could be beneficial. As for the 2nd variation you tried that looks like i'd work in my opinion. Maybe get Firebug (Firefox Plugin) and see if any errors occur.

SmileUK
30-01-2009, 04:53 PM
I suggest using unobtrusive javascript which means no inline javascript which allows you to manage it easier. If you want I could possible convert it to jQuery - I know this is not what you asked, but I think it could be beneficial. As for the 2nd variation you tried that looks like i'd work in my opinion. Maybe get Firebug (Firefox Plugin) and see if any errors occur.
How do I use that then?
I'm using http://dynamicdrive.com/dynamicindex17/ajaxcontent.htm that script.

I'll try that Firebug thing

SmileUK
05-02-2009, 06:07 PM
bump.

anyone help?

MrCraig
05-02-2009, 08:28 PM
Ummm i dont think you can have the action as loading a javascript page lool, You'll need to make a function that converts the form data into $_GET data for example and load the page with JS using the parameters for $_GET and process that way if that makes any sense to you?

Moh
05-02-2009, 08:39 PM
To submit a form via javascript, I would use prototype.

Simplest way =D



<script>
function submitRequest()
{
habboname = document.getElementById('habboname').value;
type = document.getElementById('type').value;
dj_name = document.getElementById('dj_name').value;
request = document.getElementById('request').value;

new Ajax.Request('sendrequest.php',
{
parameters: {habboname: habboname, type: type, dj_name: dj_name, request: request},
onSuccess: function(transport)
{
$('content').innerHTML = transport.responseText;
}
});
}
</script>


then for your form:



<form action="javascript: submitRequest();" method="post">

Want to hide these adverts? Register an account for free!