I have created a form on my website but for some reason 3 sections of the form arenot submitting correctly. After clicking submit I recieve this on screen:
'We are very sorry, but there were error(s) found with the form you submitted. These errors appear below.
The RAID you entered do not appear to be valid.
The Accessories you entered do not appear to be valid.
The Guarantee you entered do not appear to be valid.
Please go back and fix these errors.'
This is the PHP for the form: -
if(isset($_POST['email'])) {
-
-
$email_to = "matt.email@gmail.com";
-
-
$email_subject = "Custom Form";
-
-
-
function died($error) {
-
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
-
echo "These errors appear below.<br /><br />";
-
echo $error."<br /><br />";
-
echo "Please go back and fix these errors.<br /><br />";
-
die();
-
}
-
if(!isset($_POST['first_name']) ||
-
!isset($_POST['last_name']) ||
-
!isset($_POST['email']) ||
-
!isset($_POST['role']) ||
-
!isset($_POST['ram']) ||
-
!isset($_POST['raid']) ||
-
!isset($_POST['hdd1']) ||
-
!isset($_POST['hdd2']) ||
-
!isset($_POST['os']) ||
-
!isset($_POST['gpu']) ||
-
!isset($_POST['extras']) ||
-
!isset($_POST['accessories']) ||
-
!isset($_POST['guarantee']) ||
-
!isset($_POST['customer']) ||
-
!isset($_POST['budget'])) {
-
}
-
-
$first_name = $_POST['first_name'];
-
$last_name = $_POST['last_name'];
-
$email_from = $_POST['email'];
-
$Role = $_POST['role'];
-
$Memory_Size = $_POST['ram'];
-
$RAID = $_POST['raid'];
-
$Hard_Drive_1 = $_POST['hdd1'];
-
$Hard_Drive_2 = $_POST['hdd2'];
-
$Operating_System = $_POST['os'];
-
$Graphics_Card = $_POST['gpu'];
-
$Optional_Extras = $_POST['extras'];
-
$Accessory_Packs = $_POST['accessories'];
-
$Guarantee = $_POST['guarantee'];
-
$Customer_Specifics = $_POST['customer'];
-
$Maximum_Budget = $_POST['budget'];
-
-
$error_message = "";
-
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
-
if(!preg_match($email_exp,$email_from)) {
-
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
-
}
-
$string_exp = "/^[A-Za-z .'-]+$/";
-
if(!preg_match($string_exp,$first_name)) {
-
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
-
}
-
if(!preg_match($string_exp,$last_name)) {
-
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
-
}
-
if(strlen($Role) < 2) {
-
$error_message .= 'The Role you entered do not appear to be valid.<br />';
-
}
-
if(strlen($Memory_Size) < 2) {
-
$error_message .= 'The RAM you entered do not appear to be valid.<br />';
-
}
-
if(strlen($RAID) < 2) {
-
$error_message .= 'The RAID you entered do not appear to be valid.<br />';
-
}
-
if(strlen($Hard_Drive_1) < 2) {
-
$error_message .= 'The HHD1 you entered do not appear to be valid.<br />';
-
}
-
if(strlen($Hard_Drive_2) < 2) {
-
$error_message .= 'The HDD2 you entered do not appear to be valid.<br />';
-
}
-
if(strlen($Operating_System) < 2) {
-
$error_message .= 'The OS you entered do not appear to be valid.<br />';
-
}
-
if(strlen($Graphics_Card) < 2) {
-
$error_message .= 'The GPU you entered do not appear to be valid.<br />';
-
}
-
if(strlen($Optional_Extras) < 2) {
-
$error_message .= 'The Extras you entered do not appear to be valid.<br />';
-
}
-
if(strlen($Accessory_Packs) < 2) {
-
$error_message .= 'The Accessories you entered do not appear to be valid.<br />';
-
}
-
if(strlen($Guarantee) < 2) {
-
$error_message .= 'The Guarantee you entered do not appear to be valid.<br />';
-
}
-
if(strlen($Customer_Specifics) < 2) {
-
$error_message .= 'The Customer Specifics you entered do not appear to be valid.<br />';
-
}
-
if(strlen($Maximum_Budget) < 2) {
-
$error_message .= 'The Maximum Budget you entered do not appear to be valid.<br />';
-
}
-
if(strlen($error_message) > 0) {
-
died($error_message);
-
}
-
$email_message = "Form details below.\n\n";
-
-
function clean_string($string) {
-
$bad = array("content-type","bcc:","to:","cc:","href");
-
return str_replace($bad,"",$string);
-
}
-
-
$email_message .= "First Name: ".clean_string($first_name)."\n";
-
$email_message .= "Last Name: ".clean_string($last_name)."\n";
-
$email_message .= "Email: ".clean_string($email_from)."\n";
-
$email_message .= "Role: ".clean_string($Role)."\n";
-
$email_message .= "Memory Size: ".clean_string($Memory_Size)."\n";
-
$email_message .= "RAID: ".clean_string($RAID)."\n";
-
$email_message .= "Hard Drive 1: ".clean_string($Hard_Drive_1)."\n";
-
$email_message .= "Hard Drive 2: ".clean_string($Hard_Drive_2)."\n";
-
$email_message .= "Operating System: ".clean_string($Operating_System)."\n";
-
$email_message .= "Graphics Card: ".clean_string($Graphics_Card)."\n";
-
$email_message .= "Optional Extras: ".clean_string($Optional_Extras)."\n";
-
$email_message .= "Accessory Packs: ".clean_string($Accessory_Packs)."\n";
-
$email_message .= "Guarantee: ".clean_string($Guarantee)."\n";
-
$email_message .= "Customer Specifics: ".clean_string($Customer_Specifics)."\n";
-
$email_message .= "Maximum Budget: ".clean_string($Maximum_Budget)."\n";
-
-
// create email headers
-
$headers = 'From: '.$email_from."\r\n".
-
'Reply-To: '.$email_from."\r\n" .
-
'X-Mailer: PHP/' . phpversion();
-
@mail($email_to, $email_subject, $email_message, $headers);
-
?>
-
-
-
Thank you for requesting a quote.
-
-
<?php
-
}
-
die();
-
?>
-
-
<body>
-
</body>
-
</html>
-
-
I was getting the error for every field entered but seems to just be the three now.
So what are you suggesting I do?
I know I have to change this: -
if(strlen($RAID) < raid (4) Y (1), N (1)) {
-
$error_message .= 'The RAID you entered do not appear to be valid.<br />';
-
}
-
-
for the respective parts which are not working, I just don't know what to.
55 4504
can you print out the invalid values?
This is the PHP sections for the RAID field, as well as the relevant HTML. - !isset($_POST['raid']) ||
-
-
$RAID = $_POST['raid'];
-
-
if(strlen($RAID) < 2) {
-
$error_message .= 'The RAID you entered do not appear to be valid.<br />';
-
}
-
-
$email_message3 .= "RAID: ".clean_string($RAID)."\n";
-
-
<tr>
-
<td align="left" valign="top">
-
<label for="raid">RAID </label> </td>
-
<td align="left" valign="top">
-
<select name="raid">
-
<option value="raid"> </option>
-
<option value="Y">Yes*</option>
-
<option value="N">No</option>
-
</select>
-
<span class="style8">(*Requires 2 identical Hard Drives)</span></td>
-
</tr>
-
-
-
The Accessories Field: - !isset($_POST['accessories']) ||
-
-
$Accessory_Packs = $_POST['accessories'];
-
-
if(strlen($Accessory_Packs) < 2) {
-
$error_message .= 'The Accessories you entered do not appear to be valid.<br />';
-
}
-
-
$email_message9 .= "Accessory Packs: ".clean_string($Accessory_Packs)."\n";
-
-
<tr>
-
<td align="left" valign="top">
-
<label for="accessories">Accessory Packs [2]</label> </td>
-
<td align="left" valign="top">
-
<input type="checkbox" name="accessories" value="0" checked="checked"/>
-
None <br />
-
<input type="checkbox" name="accessories" value="1" />
-
Pack 1 <br />
-
<input type="checkbox" name="accessories" value="2" />
-
Pack 2 <br />
-
<input type="checkbox" name="accessories" value="3" />
-
Pack 3 <br />
-
<input type="checkbox" name="accessories" value="4" />
-
Pack 4 <br />
-
<input type="checkbox" name="accessories" value="5" />
-
Pack 5 <br />
-
<input type="checkbox" name="accessories" value="6" />
-
Pack 6 <br />
-
<input type="checkbox" name="accessories" value="Other" />
-
Other (Please Specify) <br /> </select> </td>
-
</tr>
-
-
-
The Guarantee Field: - !isset($_POST['guarantee']) ||
-
-
$Guarantee = $_POST['guarantee'];
-
-
if(strlen($Guarantee) < 2) {
-
$error_message .= 'The Guarantee you entered do not appear to be valid.<br />';
-
}
-
-
$email_message10 .= "Guarantee: ".clean_string($Guarantee)."\n";
-
-
<tr>
-
<td align="left" valign="top">
-
<label for="guarantee">Guarantee </label> </td>
-
<td align="left" valign="top">
-
<select name="guarantee">
-
<option value="guarantee"> </option>
-
<option value="0">No Extension</option>
-
<option value="1">1 Year Extension</option>
-
<option value="2">2 Year Extension</option>
-
</select></td>
-
</tr>
-
-
-
in pretty much every case, you mark valid answers as invalid.
Raid:
- values (strlen): raid (4), Y (1), N (1)
Accessories:
- values (strlen): 0 (1), 1 (1), … , 6 (1), Other (5)
Guarantee:
- values (strlen): guarantee (9), 0 (1), 1 (1), 2 (1)
So how do I get around this. I only understand basic PHP so I'm not very good at it.
change the condition for a failure.
example: you expect only integers to be given ( $_POST['myint']) - $value = filter_input(INPUT_POST, "myint", FILTER_VALIDATE_INT);
-
if (false === $value)
-
{
-
// myint is not an integer
-
}
Hi, I've attempted some changes to the values on the PHP however it appears to have made things worse!
I now recieve these error messages:
We are very sorry, but there were error(s) found with the form you submitted. These errors appear below.
The RAID you entered do not appear to be valid.
The Accessories you entered do not appear to be valid.
The Guarantee you entered do not appear to be valid.
The Maximum Budget you entered do not appear to be valid.
Please go back and fix these errors.
This is the code for the error messages: -
$error_message = "";
-
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
-
if(!preg_match($email_exp,$email_from)) {
-
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
-
}
-
$string_exp = "/^[A-Za-z .'-]+$/";
-
if(!preg_match($string_exp,$first_name)) {
-
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
-
}
-
if(!preg_match($string_exp,$last_name)) {
-
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
-
}
-
if(strlen($Role) < 2) {
-
$error_message .= 'The Role you entered do not appear to be valid.<br />';
-
}
-
if(strlen($Memory_Size) < 2) {
-
$error_message .= 'The RAM you entered do not appear to be valid.<br />';
-
}
-
if(strlen($RAID) < 2) {
-
$error_message .= 'The RAID you entered do not appear to be valid.<br />';
-
}
-
if(strlen($Hard_Drive_1) < 2) {
-
$error_message .= 'The HHD1 you entered do not appear to be valid.<br />';
-
}
-
if(strlen($Hard_Drive_2) < 2) {
-
$error_message .= 'The HDD2 you entered do not appear to be valid.<br />';
-
}
-
if(strlen($Operating_System) < 2) {
-
$error_message .= 'The OS you entered do not appear to be valid.<br />';
-
}
-
if(strlen($Graphics_Card) < 2) {
-
$error_message .= 'The GPU you entered do not appear to be valid.<br />';
-
}
-
if(strlen($Optional_Extras) < 2) {
-
$error_message .= 'The Extras you entered do not appear to be valid.<br />';
-
}
-
if(strlen($Accessory_Packs) < 2) {
-
$error_message .= 'The Accessories you entered do not appear to be valid.<br />';
-
}
-
if(strlen($Guarantee) < 2) {
-
$error_message .= 'The Guarantee you entered do not appear to be valid.<br />';
-
}
-
$string_exp = "/^[A-Za-z .'-]+$/";
-
if(!preg_match($string_exp,$Customer_Specifics)) {
-
$error_message .= 'The Customer Specifics you entered do not appear to be valid.<br />';
-
}
-
$string_exp = "/^[A-Za-z .'-]+$/";
-
if(!preg_match($string_exp,$Maximum_Budget)) {
-
$error_message .= 'The Maximum Budget you entered do not appear to be valid.<br />';
-
}
-
if(strlen($error_message) > 0) {
-
died($error_message);
-
}
-
I assume it's this ' if(strlen($Guarantee) < 2) {' that needs to be changed for the ones flagging as Errors. What should they be changed to?
Im assuming that it's this section ' if(strlen($Guarantee) < 2) {' that needs to be changed for the ones flagging as Errors (RAID, Accessories, Guarantee). What would you suggest setting them as?
What would you suggest setting them as?
what values do you expect (do you have given in the HTML)?
if you set numbers, check for a number (e.g. post #6), if you set strings, check if the received string matches one of the valid strings.
RAID HTML is - <tr>
-
<td align="left" valign="top">
-
<label for="raid">RAID </label> </td>
-
<td align="left" valign="top">
-
<select name="raid">
-
<option value="raid" selected="selected"> </option>
-
<option value="Y">Yes*</option>
-
<option value="N">No</option>
-
</select>
-
<span class="style8">(*Requires 2 identical Hard Drives)</span></td>
-
</tr>
Accessories HTML is - <tr>
-
<td align="left" valign="top">
-
<label for="accessories">Accessory Packs [2]</label> </td>
-
<td align="left" valign="top">
-
<input type="checkbox" name="accessories" value="0" checked="checked"/>
-
None <br />
-
<input type="checkbox" name="accessories" value="1" />
-
Pack 1 <br />
-
<input type="checkbox" name="accessories" value="2" />
-
Pack 2 <br />
-
<input type="checkbox" name="accessories" value="3" />
-
Pack 3 <br />
-
<input type="checkbox" name="accessories" value="4" />
-
Pack 4 <br />
-
<input type="checkbox" name="accessories" value="5" />
-
Pack 5 <br />
-
<input type="checkbox" name="accessories" value="6" />
-
Pack 6 <br />
-
<input type="checkbox" name="accessories" value="Other" />
-
Other (Please Specify) <br /> </select> </td>
-
</tr>
Guarantee HTML is: - <tr>
-
<td align="left" valign="top">
-
<label for="guarantee">Guarantee </label> </td>
-
<td align="left" valign="top">
-
<select name="guarantee">
-
<option value="guarantee" selected="selected"> </option>
-
<option value="0">No Extension</option>
-
<option value="1">1 Year Extension</option>
-
<option value="2">2 Year Extension</option>
-
</select></td>
-
</tr>
I think (hope) with that you can answer the question what values you expect for each field.
Honestly have no idea. I've only recently started using PHP.
this has nothing to do with PHP. this is pure HTML (at this point):
what are the possible values for the guarantee field?
guarantee, 0, 1, 2. So 4 values?
4 possible values, of which one will be (regularly) submitted.
what does the value "guarantee" stand for?
a 'tab' space, so appearance is blank on the form.
I changed Guarantee to - if(strlen($Guarantee) < 4) {
-
$error_message .= 'The Guarantee you entered do not appear to be valid.<br />';
-
}
but still recieve an error when submitting the form.
Also attempted this with RAID: -
if(strlen($RAID) < 3) Y (1), N (2)) {
-
$error_message .= 'The RAID you entered do not appear to be valid.<br />';
-
}
but instead recieve a Parse Error: Parse error: syntax error, unexpected ',' in /www/zymichost.com/m/y/c/mycustombuiltpc/htdocs/CustomForm.php on line 75
of course. there are 3 valid values with a string length < 4 (the numbers). does the "guarantee" value bear any meaning (to the script)? if not, it can be regarded as invalid value and then you only have the numbers left, for which I already showed you a way to verify them.
I have now tried it as you suggested, Raid:
- values (strlen): raid (4), Y (1), N (1)
as - if(strlen($RAID) < raid (4) Y (1), N (1)) {
-
$error_message .= 'The RAID you entered do not appear to be valid.<br />';
-
}
But still get the Parse Error.
Guarantee " " will never be selected, so will never be a chosen value.
I have now tried it as you suggested, Raid:
- values (strlen): raid (4), Y (1), N (1)
that wasn’t a suggestion, just what strlen() on that values would produce.
Guarantee " " will never be selected, so will never be a chosen value.
that leaves you with the numbers. and I already showed you how to validate numbers. (but you are aware that " " won’t be passed, ain’t you?)
So I would just need to put - if(strlen($Guarantee) < (3) {
do you know what the strlen() function does?
I believed it is for a string, I'm assuming I'm wrong?
yea, but what does it actually do?
Returns the length of the string?
correct.
does that functionality (returning the string length) help you validating the input?
I'm guessing not as it isn't working.
disregarding PHP, describe in words how you you would determine, when the input of the guarantee field is valid.
It's a drop down menu, so whenever one of the 3 options are selected, 4 fields, "[blank]", none, 1 yr extension, 2 yr extension
none, 1 yr extension, 2 yr extension
now we have the meaning (intention) of the choosable options, but what are the values sent to the server script?
Not really sure, assuming a number(s)?
and how would you check if something is a number?
edit: hey, this is my 6,000th post!
I'm not really sure. Error messages shouldn't have '$strlen' is about as far as I'm following, although it's sending numbers, but it shouldn't.
@Dormilich
Hey Dormilich congratulations on your 6000
why shouldn’t it send numbers?
so it's sending numbers as representations of:
none, 1 yr extension, 2 yr extension?
you wrote the HTML, didn’t you?
Yes,I know how to write it, just don't understand how it then relates to the functions in PHP.
your input does not relate to PHP functions (unless I misinterpret the term "relate"). what you have is input (either from $_GET or $_POST […]) and you need to validate these strings by means of PHP function. which function(s) to choose for that purpose depends on what the input is supposed to be. e.g. strlen() gives you the length of the string, if that is a statement you can work with depends on your validation strategy.
so you're suggesting not having POST and having GET instead?
it doesn’t matter whether it is $_POST or $_GET, the validation required is the same.
So if that is all fine, then it is purely the second half of the error messages causing the problems, but I don't know/ understand what to change these to.
what was the message again?
We are very sorry, but there were error(s) found with the form you submitted. These errors appear below.
The RAID you entered do not appear to be valid.
The Accessories you entered do not appear to be valid.
The Guarantee you entered do not appear to be valid.
Please go back and fix these errors.
I thought it were a PHP error message. nevertheless, the problem is your validation strategy. the last time we were at "how would you check that a variable is an integer?" any ideas?
They are predefined error messages on the PHP which, when an error occurs, display on the screen. I honestly have no idea.
you have no idea what the difference between 1 and "q" is?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: GriffithsJ |
last post by:
Hi
I have been given some text that needs to be displayed on a web page. The
text is pre-formatted (includes things like lists etc) and displays okay if
I wrap it using the <pre/> tag. ...
|
by: Headless |
last post by:
I've marked up song lyrics with the <pre> tag because it seems the most
appropriate type of markup for the type of data. This results in
inefficient use of horizontal space due to UA's default...
|
by: Neal |
last post by:
A few questions about pre...
When presenting preformatted text using the white-space: pre;
property/value, Opera renders long lines at small viewport widths as
exiting the borders of the...
|
by: Alan Illeman |
last post by:
How do I set several different properties for PRE in
a CSS stylesheet, rather than resorting to this:
<BODY>
<PRE STYLE="font-family:monospace;
font-size:0.95em;
width:40%;
border:red 2px...
|
by: Buck Turgidson |
last post by:
I want to have a css with 2 PRE styles, one bold with large font, and
another non-bold and smaller font.
I am new to CSS (and not exactly an expert in HTML, for that matter). Is
there a way to...
|
by: Michael Shell |
last post by:
Greetings,
Consider the XHTML document attached at the end of this post.
When viewed under Firefox 1.0.5 on Linux, highlighting
and pasting (into a text editor) the <pre> tag listing will...
|
by: Jarno Suni not |
last post by:
It seems to be invalid in HTML 4.01, but valid in XHTML 1.0. Why is there the difference? Can that pose a problem when such a XHTML document is served as text/html?
|
by: Rocky Moore |
last post by:
I have a web site called HintsAndTips.com. On this site people post tips
using a very simply webform with a multi line TextBox for inputing the tip
text. This text is encode to HTML so that no...
|
by: Schraalhans Keukenmeester |
last post by:
I am building a default sheet for my linux-related pages.
Since many linux users still rely on/prefer viewing textmode and
unstyled content I try to stick to the correct html tags to pertain good...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |