Menu
Hello.
I have multiple forms on my website, and I use FormMail.pl which allows me to have code, such as:
<input type=”hidden” name=”required” value=”contactNAME,contactEMAIL,contactLANG,contactCOMMENTS”>
to make sure things are done.
Is there a way to do this with PHP though?
I.e. to submit itself to the same page, so the form i.e. <form method=”post” action=”cgi-bin/FormMail.pl” target=”_self”> would actually have action=”feedback.php” (itself) and then it validates, and if there’s errors it will echo them, if not it will send it to FormMail.pl to be sent?
Is this poss, if so how would I do it, i’m rather new, so sorry.
thanks.
[code=php]if (empty($_POST['fieldname'])) {
echo "Please fill out 'fieldname'";
exit();
}[/code]
[code=php]
<?php
include("header.php");
if (empty($_POST['contactNAME'])) {
echo "Your name cannot be blank.";
exit();
}
if (preg_match('/[^x00-x20()<>@,;:".[]x7f-xff]+(?:.[^x00-x20()<>@,;:".[]x7f-xff]+)*@[^x00-x20()<>@,;:".[]x7f-xff]+(?:.[^x00-x20()<>@,;:".[]x7f-xff]+)+/i', $_POST['contactEMAIL'])) {
echo "Address is valid";
}
else {
echo "Your E-mail address is invalid.";
}
if (empty($_POST['contactCOMMENTS'])) {
echo "Your comments cannot be blank.";
exit();
}
?>
my form goes here . . .
<?php include("footer.php"); ?>
[/code]
[code=php]
<?PHP
if (empty($_POST['contactNAME'])) {
echo "Your name cannot be blank.";
exit();
}
if (preg_match('/[^x00-x20()<>@,;:\".[]x7f-xff]+(?:.[^x00-x20()<>@,;:\".[]x7f-xff]+)*@[^x00-x20()<>@,;:\".[]x7f-xff]+(?:.[^x00-x20()<>@,;:\".[]x7f-xff]+)+/', $_POST['contactEMAIL'])) {
echo "Your E-mail is invalid.";
exit();
}
if (empty($_POST['contactCOMMENTS'])) {
echo "Your comments cannot be blank.";
exit();
}
if (!isset ($_POST['TERMSon'])) {
echo "You must accept the terms.";
exit();
}
#######################################################
# This script is Copyright 2003, Infinity Web Design #
# Distributed by http://www.webdevfaqs.com #
# Written by Ryan Brill - [email][email protected][/email] #
# All Rights Reserved - Do not remove this notice #
#######################################################
## The lines below need to be edited...
###################### Set up the following variables ######################
#
$to = "[email protected]"; #set address to send form to
$subject = "Results from your web form."; #set the subject line
$headers = "From: [email][email protected][/email]"; #set the from address, or any other headers
$forward = 1; # redirect? 1 : yes || 0 : no
$location = "thanks.php"; #set page to redirect to, if 1 is above
#
##################### No need to edit below this line ######################
## set up the time ##
$date = date ("l, F jS, Y");
$time = date ("h:i A");
## mail the message ##
$msg = "Below is the result of your feedback form. It was submitted on $date at $time.nn";
if ($_SERVER['REQUEST_METHOD'] == "POST") {
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "n";
}
}
else {
foreach ($_GET as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "n";
}
}
mail($to, $subject, $msg, $headers);
if ($forward == 1) {
header ("Location:$location");
}
else {
echo "Thank you for submitting our form. We will get back to you as soon as possible.";
}
?>
[/code]
<i>
</i>1. How do I get all the errors to be displayed at once if there are any - at the moment it goes through until one is corrected, then displays the next, etc.
2. How can I get it to use my header/footer.php if there's an error so they show nicely on in the theme (or is it even possible to have them echoe'd onto the form.php itself? (not something i really need...).
3. I think i've really screwed up the e-mail part, what did i do wrong, it doesn't seem to do much if anything, or is it not validating whether the mail is correct? not sure what i've done , i just want it to echo that error if it's wrong.
[code=php]
<?PHP
if (empty($_POST['contactNAME'])) {
echo "Your name cannot be blank.";
exit();
}
if (preg_match('/[^x00-x20()<>@,;:".[]x7f-xff]+(?:.[^x00-x20()<>@,;:".[]x7f-xff]+)*@[^x00-x20()<>@,;:".[]x7f-xff]+(?:.[^x00-x20()<>@,;:".[]x7f-xff]+)+/', $_POST['contactEMAIL'])) {
echo "Your E-mail is invalid.";
exit();
}
if (empty($_POST['contactCOMMENTS'])) {
echo "Your comments cannot be blank.";
exit();
}
if (!isset ($_POST['TERMSon'])) {
echo "You must accept the terms.";
exit();
}
##################################################
#####
# This script is Copyright 2003, Infinity Web Design #
# Distributed by <a href="http://www.webdevfaqs.com" target="_blank">http://www.webdevfaqs.com</a> #
# Written by Ryan Brill - [email][email protected][/email] #
# All Rights Reserved - Do not remove this notice #
##################################################
#####
## The lines below need to be edited...
###################### Set up the following variables ######################
#
$to = "[email protected]"; #set address to send form to
$subject = "Results from your web form."; #set the subject line
$headers = "From: [email][email protected][/email]"; #set the from address, or any other headers
$forward = 1; # redirect? 1 : yes || 0 : no
$location = "thanks.php"; #set page to redirect to, if 1 is above
#
##################### No need to edit below this line ######################
## set up the time ##
$date = date ("l, F jS, Y");
$time = date ("h:i A");
## mail the message ##
$msg = "Below is the result of your feedback form. It was submitted on $date at $time.nn";
if ($_SERVER['REQUEST_METHOD'] == "POST") {
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "n";
}
}
else {
foreach ($_GET as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "n";
}
}
mail($to, $subject, $msg, $headers);
if ($forward == 1) {
header ("Location:$location");
}
else {
echo "Thank you for submitting our form. We will get back to you as soon as possible.";
}
?>
[/code]
<?PHP
$msg = "";
if (empty($_POST['contactNAME'])) {
$msg .= "Your name cannot be blank.<br>";
}
if (!preg_match('/[^x00-x20()<>@,;:\".[]x7f-xff]+(?:.[^x00-x20()<>@,;:\".[]x7f-xff]+)*@[^x00-x20()<>@,;:\".[]x7f-xff]+(?:.[^x00-x20()<>@,;:\".[]x7f-xff]+)+/', $_POST['contactEMAIL'])) {
$msg .= "Your E-mail is invalid.<br>";
}
if (empty($_POST['contactCOMMENTS'])) {
$msg .= "Your comments cannot be blank.<br>";
}
if (!isset ($_POST['TERMSon'])) {
$msg .= "You must accept the terms.<br>";
}
if (!empty($msg)) {
include "header.php"; # include your header
echo "<p>$msg</p>";
include "footer.php"; # include your footer
}
#######################################################
# This script is Copyright 2003, Infinity Web Design #
# Distributed by <a href="http://www.webdevfaqs.com">http://www.webdevfaqs.com</a> #
# Written by Ryan Brill - [email][email protected][/email] #
# All Rights Reserved - Do not remove this notice #
#######################################################
## The lines below need to be edited...
###################### Set up the following variables ######################
#
$to = "[email protected]"; #set address to send form to
$subject = "Results from your web form."; #set the subject line
$headers = "From: [email][email protected][/email]"; #set the from address, or any other headers
$forward = 1; # redirect? 1 : yes || 0 : no
$location = "thanks.php"; #set page to redirect to, if 1 is above
#
##################### No need to edit below this line ######################
## set up the time ##
$date = date ("l, F jS, Y");
$time = date ("h:i A");
## mail the message ##
$msg = "Below is the result of your feedback form. It was submitted on $date at $time.nn";
if ($_SERVER['REQUEST_METHOD'] == "POST") {
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "n";
}
}
else {
foreach ($_GET as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "n";
}
}
mail($to, $subject, $msg, $headers);
if ($forward == 1) {
header ("Location:$location");
}
else {
echo "Thank you for submitting our form. We will get back to you as soon as possible.";
}
?>
[code=php]if (!empty($msg)) {
include "header.php"; # include your header
echo "<p>$msg</p>";
include "footer.php"; # include your footer
exit();
}[/code]
[code=php]
<?PHP
$msg = "";
if (empty($_POST['contactNAME'])) {
$msg .= "Your name cannot be blank.<br />";
}
if (!preg_match('/[^x00-x20()<>@,;:\".[]x7f-xff]+(?:.[^x00-x20()<>@,;:\".[]x7f-xff]+)*@[^x00-x20()<>@,;:\".[]x7f-xff]+(?:.[^x00-x20()<>@,;:\".[]x7f-xff]+)+/', $_POST['contactEMAIL'])) {
$msg .= "Your E-mail address is invalid.<br />";
}
if (empty($_POST['contactCOMMENTS'])) {
$msg .= "Your comments cannot be blank.<br />";
}
if (!isset ($_POST['TERMSon'])) {
$msg .= "You must accept the terms.<br />";
}
if (!empty($msg)) {
include "header.php"; # include your header
echo "<br />$msg<br />";
include "footer.php"; # include your footer
exit();
}
#######################################################
# This script is Copyright 2003, Infinity Web Design #
# Distributed by http://www.webdevfaqs.com #
# Written by Ryan Brill - [email][email protected][/email] #
# All Rights Reserved - Do not remove this notice #
#######################################################
## The lines below need to be edited...
###################### Set up the following variables ######################
#
$to = "[email protected]"; #set address to send form to
$subject = "Results from your web form."; #set the subject line
$headers = "From: [email][email protected][/email]"; #set the from address, or any other headers
$forward = 1; # redirect? 1 : yes || 0 : no
$location = "thanks.php"; #set page to redirect to, if 1 is above
#
##################### No need to edit below this line ######################
## set up the time ##
$date = date ("l, F jS, Y");
$time = date ("h:i A");
## mail the message ##
$msg = "Below is the result of your feedback form. It was submitted on $date at $time.nn";
$msg .= "IP: ".$_SERVER['REMOTE_ADDR']."nn";
if ($_SERVER['REQUEST_METHOD'] == "POST") {
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "n";
}
}
else {
foreach ($_GET as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "n";
}
}
mail($to, $subject, $msg, $headers);
if ($forward == 1) {
header ("Location:$location");
}
else {
echo "Thank you for submitting our form. We will get back to you as soon as possible.";
}
?>
[/code]
[code=php]
if (!empty($msg)) {
include "header.php"; # include your header
echo "<br />$msg<br />";
echo "<input type="button" class="option" value="< Back" onclick="history.back()"><br />";
include "footer.php"; # include your footer
exit();
}
[/code]
[code=php]
if (exists $_POST[valadator]){
[/code]
[code=php]
}
[/code]
<i>
</i><input type=hidden name=valadator>
[code=php]
if (empty($_POST['TIMEZONE'])) {
$msg .= "Your select a timezone.<br />";
}
[/code]
[i]Originally posted by Teach [/i]
[B]I have a table full of checkboxes which is for a pattern of times, how can i check whether something within that table is selected[/b][/quote]
[i]Originally posted by Teach [/i]
[b]pyro do you understand the post before, what does it mean / what did i do wrong?[/b][/quote]
[code=php]
<?PHP
$msg = "";
if (empty($_POST['contactNAME'])) {
$msg .= "Your name cannot be left blank.<br />";
}
if (empty($_POST['siteUSERNAME'])) {
$msg .= "Your username cannot be left blank.<br />";
}
if (!preg_match('/[^x00-x20()<>@,;:\".[]x7f-xff]+(?:.[^x00-x20()<>@,;:\".[]x7f-xff]+)*@[^x00-x20()<>@,;:\".[]x7f-xff]+(?:.[^x00-x20()<>@,;:\".[]x7f-xff]+)+/', $_POST['contactEMAIL'])) {
$msg .= "Your E-mail address is invalid.<br />";
}
if (!isset ($_POST['TERMSon'])) {
$msg .= "You must accept the terms.<br />";
}
if (!empty($msg)) {
include "../header.php"; # include your header
echo "<p>$msg</p>";
include "../footer.php"; # include your footer
exit();
}
#######################################################
# This script is Copyright 2003, Infinity Web Design #
# Distributed by http://www.webdevfaqs.com #
# Written by Ryan Brill - [email][email protected][/email] #
# All Rights Reserved - Do not remove this notice #
#######################################################
## The lines below need to be edited...
###################### Set up the following variables ######################
#
$to = "[email protected]"; #set address to send form to
$subject = "Results from your web form."; #set the subject line
$headers = "From: [email][email protected][/email]"; #set the from address, or any other headers
$forward = 1; # redirect? 1 : yes || 0 : no
$location = "thanks.php"; #set page to redirect to, if 1 is above
#
##################### No need to edit below this line ######################
## set up the time ##
$date = date ("l, F jS, Y");
$time = date ("h:i A");
## mail the message ##
$msg = "Below is the result of your feedback form. It was submitted on $date at $time.nn";
$msg .= "IP: ".$_SERVER['REMOTE_ADDR']."nn";
if ($_SERVER['REQUEST_METHOD'] == "POST") {
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "n";
}
}
else {
foreach ($_GET as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "n";
}
}
mail($to, $subject, $msg, $headers);
if ($forward == 1) {
header ("Location:$location");
}
else {
echo "Thank you for submitting our form. We will get back to you as soon as possible.";
}
?>
[/code]
[code=php]if (!preg_match("/^[a-zA-Z0-9]+$/", $variable)) {
$msg .= "That field must only contain A-Z, a-z and 0-9";
}[/code]
[code=php]
if (empty($_POST['siteUSERNAME'])) {
$msg .= "Your username cannot be blank.<br />";
}
if (!preg_match("/^[a-zA-Z0-9]+$/", $siteUSERNAME)) {
$msg .= "That field must only contain A-Z, a-z and 0-9";
}
[/code]
[code=php]
if (!preg_match("/^[a-zA-Z0-9]+$/", $siteUSERNAME)) {
$msg .= "That field must only contain A-Z, a-z and 0-9";
}
[/code]
0.1.9 — BETA 6.16