...

View Full Version : Redirect and Submit Button



Nexusfactor
12-07-2010, 06:16 PM
Hello

Wondering something, I created a form and have I have it submit when the user clicks the Submit button.



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Assignment 4</title>
<style type="text/css">
</style>
</head>

<body style="color: #009999; background-color: #000000">

<form action="mailto:whatisthematrix01@hotmail.com" name="frmCustomer" method="post">

<table style="width: 85%; height: 222px;">
<tr>
<td>
<img alt="Space Ship" height="223" src="spaceship_cg2.jpg" style="float: left" width="761" /></td>
</tr>
</table>

<p>&nbsp;</p>
<table style="width: 100%">
<tr>
<td class="style1">Interstellar Shipping - Customer Registration </td>
</tr>
</table>
<p>&nbsp;</p>

<table class="style2">
<tr>
<td class="style3">
First Name:</td>
<td colspan="2" style="width: 273px">
<input id="Text1" type="text" name="Fname" /></td>
</tr>
<tr>
<td class="style3">
Last Name</td>
<td colspan="2" style="width: 273px">
<input id="Text2" type="text" name="Lname" /></td>
</tr>
<tr>
<td class="style3">
City: </td>
<td colspan="2" style="width: 273px">
<input id="Text3" type="text" name="UseCity" /></td>
</tr>
<tr>
<td class="style3">
Country:</td>
<td colspan="2" style="width: 273px">
<input id="Text4" type="text" name="UserCountry" /></td>
</tr>
<tr>
<td class="style3">
E-Mail:</td>
<td colspan="2" style="width: 273px">
<input id="Text6" name="userEmail" type="text" /></td>
</tr>
<tr>
<td class="style3">
Username:</td>
<td colspan="2" style="width: 273px">
<input id="Text5" type="text" name="Username" /></td>
</tr>
<tr>
<td class="style3">
Password:</td>
<td colspan="2" style="width: 273px">
<input id="Password1" type="password" name="Userpassword" /></td>
</tr>
<tr>
<td class="style3" style="height: 35px">
Gender:</td>
<td style="width: 307px; height: 35px;">
Male
<input name="radGender" type="radio" value="radMale" /> Female
<input name="radGender" type="radio" value="radFemale" /></td>
<td style="width: 273px; height: 35px;">
</td>
</tr>
<tr>
<td class="style3">
<input id="Submit1" type="button" value="submit" onclick="doSave()"/></td>
<td colspan="2" style="width: 273px">
<input id="Reset1" type="reset" value="reset" /></td>
</tr>
</table>
</form>


<script Language = "JavaScript">



function ltrim(varIn)
{/*Purpose: Trims the leading spaces from a string*/
var varOut = ""

if(!varIn)
{
// string is null, so nothing to do
}
else // string has at least one character
{
for(intI=0; intI < varIn.length; intI++)
{
if(varIn.charAt(intI) != " ")
{
//first non-space char found so return
//string from this character forward
varOut = varIn.substring(intI)
break
}
}
}
return varOut
}

function doSave()
{

var fOk = true
var strSuperMessage
var superFirstName = document.frmCustomer.Fname
var superLastName = document.frmCustomer.Lname
var superUserCity = document.frmCustomer.UseCity
var superUserName = document.frmCustomer.Username
var superUserPassword = document.frmCustomer.Userpassword
var superUserEmail = document.frmCustomer.userEmail

var checkDigit = /\d/;

if ((ltrim(superFirstName.value)).length == 0)
{
fOk = false
strSuperMessage = "First Name Required"
superFirstName.focus()
}
else
{
if ((ltrim(superLastName.value)).length == 0)
{
fOk = false
strSuperMessage = "Last Name Required"
superLastName.focus()

}
else
{
if ((ltrim(superUserCity.value)).length == 0)
{
fOk = false
strSuperMessage = "City Required"
superUserCity.focus()
}

else
{
if ((ltrim(superUserName.value)).length == 0)
{
fOk = false
strSuperMessage = "Username Required"
superUserName.focus()


}


else
{
if ((ltrim(superUserEmail.value)).length == 0)
{
fOk = false
strSuperMessage = "E-Mail Required"
superUserEmail.focus()
}

else
{
if
(superUserEmail.value.indexOf("@") == -1
|| superUserEmail.value.indexOf(".")== -1)
{
fOk = false
strSuperMessage = "The entered e-mail address is not " +
"valid.\nE-mail addresses must " +
"be in the form name@domain."
superUserEmail.focus()
}
else
{

if (superUserPassword.value.search(checkDigit) ==-1)
{
fOk=false
strSuperMessage = "Please enter at least one digit in your password field.";
superUserPassword.focus()


}

else
{
if ((document.frmCustomer.radGender[0].checked==false) &&
(document.frmCustomer.radGender[1].checked==false))
{
fOk = false
strSuperMessage = "Gender Required"
}


}
}
}}}}}

if(fOk)
{
document.frmCustomer.submit();
//window.location="http://www.google.com"
}

else
alert(strSuperMessage)
}

</script>

</body>
</html>

Is it okay if I redirect to Google like I did here.

if(fOk)
{
document.frmCustomer.submit();
//window.location="http://www.google.com"
}

I can't do it in the form action, because I have the mailto link. Simply put, what I did in the if statement, is that okay, there would be no problem with it?

Philip M
12-07-2010, 06:46 PM
You can only redirect after a form submit using server-side scripting. Javascript cannot do that.

The trouble with using mailto: to send form results is its unpredictability. The method it is highly dependent on the browser in use and the email client in use (some people have only Yahoo or Hotmail). In particular, your visitor must have Outlook or Outlook Express as the default client for this to work correctly. Even if your visitor is using Internet Explorer, but the default mail client is different (e.g. Eudora), your mailto form will not work. With all of the browser troubles, you're likely to lose about half of your users' messages. Most of the email clients that can successfully send a mail will prompt the user by a security dialog prior to sending - this can scare many users from continuing. Also, what about people with Javascript disabled?

If you are going to use a form then use a server-side formmail script as the action - there are several good free ones out there.


BTW, when posting here please follow the posting guidelines and wrap your code in CODE tags. This means use the octothorpe or # button on the toolbar. You can (and should) edit your previous post.


Lottery: A tax on people who are bad at math.

mlseim
12-07-2010, 08:28 PM
Who is your webhost, and why can't you use PHP to process the form?

If you can't use PHP (or Perl) ... you can't process the form.

Nexusfactor
12-08-2010, 01:39 AM
I am using my school's server, however, a little Google searching revealed that php and hotmail don't mix. However, this javascript page I was just wondering if it was okay to do the redirect where I did it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum