PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
i have truly exhausted all resources (to the best of my knowledge) in solving this problem. i read the posting guidelines and didn't understand the tag references, so pls forgive me with this first post.
i have a form that i want to be completed, validated, then directed to another file to process the database insert command. i had already created this form with a validation script that worked perfectly and was hoping to make "minor" adjustments to it. here's the script in part:
<HTML>
<head>
<script language="JavaScript" type="text/javascript">
function Validatemercy()
{
var method = document.mercy.ContactMethod;
var email = document.mercy.EmailAddress;
var address = document.mercy.PostalAddress;
if (method.selectedIndex < 1)
{
alert("Please provide your preferred method of contact.");
method.focus();
return false;
}
if ((method.selectedIndex==1) && (email.value == ""))
{
window.alert("Please enter your email address.");
email.focus();
return false;
}
[color=darkred]return true;[/color]
}
// -->
</script>
</head>
<form name="mercy2" method="post" action='.$GLOBALS["PHP_SELF"].'onSubmit="return Validatemercy();">
<input type=submit name="sent" value="Submit Form" language="JavaScript" onclick="return validate(this)">
<INPUT TYPE=RESET VALUE="Reset Form">
</FORM>
i have no problem with the validation, but after the form is completed correctly and resubmitted, an error message (page cannot be displayed; HTTP 405 - Resource not allowed IIS) appears.
i tried to insert header("Location: help2.php"); in the return true of my if statement, but i get "page cannot be displayed" as soon as the submit button is clicked.
would any of the moderators put this guy's code in appropriate tags...
hi, do use php tags for php code
code tags for html code
if you want quote something others have said use quote
use img for images
use url tags to wrap urls
i hope these would get u started to post properly
then regarding your javascript code,
concatenate all the error messages with a newline character to separate them and display at the end when valid is false.
raghavan20 wrote:then regarding your javascript code,
concatenate all the error messages with a newline character to separate them and display at the end when valid is false.
thank u so much for reaching out to me. i do apologize again about the posting. ummm, i don't quite understand what u mean by this advice. i'm relatively new to PHP and script writing, so . . . .
<script language="JavaScript" type="text/javascript">
function Validatemercy()
{
var valid = true;//store the validity of fields
var errorMessage = "";//to store error messages
var method = document.mercy.ContactMethod;
var email = document.mercy.EmailAddress;
var address = document.mercy.PostalAddress;
if (method.selectedIndex < 1)
{
errorMessage = "Please provide your preferred method of contact." + "\n" ;
method.focus();
valid = false;
}
if ((method.selectedIndex==1) && (email.value == ""))
{
errorMessage += "Please enter your email address." + "\n" ;
email.focus();
valid = false;
}
if (valid){
return true;
}else{
return false;
alert (errorMessage);
}
}
// -->
</script>
i'm so sorry i've frustrated you! i do thank you so much, though! my form is working properly now, though i have yet to incorporate these changes you've just suggested! the header redirect is working just as it should!
i read that i could use multiple statements for a condition. the header redirect works, but the values don't store. my help2.php has this script that works fine when help2.php is the action of another form.
I dont actually understand wot you are saying??? You want these values to be accessed in the redirected page.
as you shd be knowing, its not possible to access global and local variables that are defined in one page in another. you have to either store them as session or cookie variables or pass all of them through GET or POST using a form.
raghavan20 wrote:register the array with the session
session_register($tempArray);
note: remember the following caution
session_register() wrote:If you want your script to work regardless of register_globals, you need to instead use the $_SESSION array as $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where the PHP directive register_globals is disabled.