Page 1 of 1
displaying error on page
Posted: Wed Apr 23, 2008 6:34 am
by enemeth
Hi there,
got a quick question im sure it is an easy one for everyone, 'except me' !
echo ' verification is incorrect'
that code right there , how do i get it to display in a specific place on my page?
instead of the top of my include page?
Thanks,
Elaine
Re: displaying error on page
Posted: Wed Apr 23, 2008 7:10 am
by aceconcepts
Depends on your logic. Can you show some of your code and where you want to echo.
Re: displaying error on page
Posted: Wed Apr 23, 2008 7:40 am
by enemeth
ok, here it all is, where it says include , it goes back to the page, and lets the person enter the information again , but i really dont want that to happen i really dont like pop up boxes, so i want it just to display the error message next to the verification code that was typed in wrong. instead of refreshing the whole page.....
Code: Select all
<?
session_start();
$msg = "Incorrect Verification Code, Please try again!";
if ($_POST["vercode"] != $_SESSION["vercode"] OR $_SESSION["vercode"]=='') {
echo "<script langauge=\"javascript\">alert(\"".$msg."\");</script>";
include 'recruiter.php';
exit;
} else {
$my_email = "elainenemeth@hotmail.com";
$from = $_POST['from'];
$subject = $_POST['subject'];
$message = stripslashes("Name: " . $from . "\n\n" . "Email: " . $_POST['email'] . "\n\nOther: ". $_POST['other'] . "\n\n" . "Phone: " . $_POST['phone']);
$fileatt = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];
$headers = "From: $from";
if (is_uploaded_file($fileatt)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
// Add a multipart boundary above the plain message
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
// Base64 encode the file data
$data = chunk_split(base64_encode($data));
// Add file attachment to the message
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
// Send the message
mail($my_email, $subject, $message, $headers);
echo '';
};
?>
<?php include 'header.php';?><br>
<p align="center"><strong><font face="Arial"><big>Thank you for submitting information<br>
You will be redirected shortly</big></font></strong></p>
<script>
var redirecturl="index.php"
var pausefor=5
function postaction(){
if (window.timer){
clearInterval(timer)
clearInterval(timer_2)
}
window.location=redirecturl
}
setTimeout("postaction()",pausefor*1000)
</script>
<br><br><br><br><br><br>
<img src="images/progressbar.gif"><br><br><br><br>
<?php include 'footer.php';?>
Re: displaying error on page
Posted: Wed Apr 23, 2008 9:23 am
by enemeth
any one have any ideas on how to display the error on the same page without refreshing the page ?
Thx,
Elaine
Re: displaying error on page
Posted: Wed Apr 23, 2008 10:01 am
by aceconcepts
Call the validation before you call the form.
Re: displaying error on page
Posted: Wed Apr 23, 2008 10:18 am
by enemeth
i dont want to have people click submit to verify the code , then submit to send the information, i just want the error 'incorrect code' to display next to it , instead of on a pop up box and not let them continue until they get it right.... possible?
Re: displaying error on page
Posted: Wed Apr 23, 2008 10:34 am
by aceconcepts
I meant if you literally place the validation code before the other code the "check if submit" clause --- if(isset($_POST['submit']) --- will enable validation only if they submit the form.
Is that clear?
Re: displaying error on page
Posted: Wed Apr 23, 2008 12:25 pm
by enemeth
it should be, but it isnt, i dont no where to put it,

Re: displaying error on page
Posted: Wed Apr 23, 2008 1:51 pm
by aceconcepts
So what you're doing is submitting data from one page to another, yeah?
Re: displaying error on page
Posted: Wed Apr 23, 2008 2:10 pm
by enemeth
No i am letting people apply to be a recruiter , or apply for jobs
go see: its not finish
http://middlemancan.bmtwebdesign.com/recruiter.php
its a simple form that people can upload there resume, but i had problems when i first put it up, alot of spam, so i implemented the image verification thingy, and now when you put in a wrong code let say it gives a pop up that says its wrong, and to try again, but i really dont like the pop up i would rather the error telling them it is wrong, goes next to the box where they entered the verification code instead...
thats it
Elaine
thank you for helping me

Re: displaying error on page
Posted: Wed Apr 23, 2008 2:21 pm
by aceconcepts
It looks like you embedded javascript is not working.
What i would do is:
Code: Select all
$vercodeErr=0;
if ($_POST["vercode"] != $_SESSION["vercode"] OR $_SESSION["vercode"]=='') {
$vercodeErr=1;
include 'recruiter.php';
exit;
inside recruiter.php near the code box:
One of the main reasons why I would do it this way is because when you rely on javascript to catch an error you are assuming that the user has javascript enabled. The method I used is executed on the server so it will always catch the error - javascript is client-side.
Re: displaying error on page
Posted: Wed Apr 23, 2008 4:14 pm
by enemeth
and the first part i put it in the submit.php file?
i tried it , but im not an expert i think i copied it all wrong,
where does it show the error?
Re: displaying error on page
Posted: Wed Apr 23, 2008 5:04 pm
by aceconcepts
This is how I usually do it:
Code: Select all
//call the script that carries out the validation
include"validation.php"; //this is where the error will be determined, and then displayed below if error exists
//form details - name textbox etc...
echo'<td width="21%" align="right" height="1"><font size="2" face="Arial">Image Verification:</font></td>
<td width="48%" height="1">';
//display error if code does not match
if($vercodeErr==1){
echo $msg . '<br />';
}
echo'<input type="text" name="vercode" /> <img src="captcha.php">
</td>';
In the validation script check the verification code:
Code: Select all
$vercodeErr=0;
if(isset($_POST['send']))
{
if ($_POST["vercode"] != $_SESSION["vercode"] OR $_SESSION["vercode"]=='') {
$vercodeErr=1;
}
}
So basically what you will be doing is:
1. calling the validation script
2. in the validation script you will check whether any data has been submitted
- if so then check code and set error variable if code is invalid
3. display the form
4. if error=1 then display error
- else process data
Hope it makes sense

Re: displaying error on page
Posted: Wed Apr 23, 2008 7:37 pm
by enemeth
Thank you ohh so much
makes good sense thank you for taking the time
*hugs*
Elaine
Re: displaying error on page
Posted: Thu Apr 24, 2008 3:11 am
by aceconcepts
No probs, let me know if you get stuck
