PDA

View Full Version : help for validating forms



chandni
04-29-2006, 10:25 AM
hello there i have this form the link is the fields marked in this form with an * name, second name are mandatory fields. i have created a form i.e. the second link which should be called when any of the mandatory fields is left blank. the second page which i have created says hit the back button of your browers and fill in the name. please help me with the script so that when i click on the submit button the form should check if the mandatory fields are not left empty. secondly, i have a doubt. i have two fields which are mandatory. do i have to create two seperate pages one to validate name and second to validate the second name. or just one form can do the work.

http://www.leximindia.com/info.html

http://www.leximindia.com/infovalidation.html

many thanks
chandni

davidundalicia
04-29-2006, 11:20 AM
Hi chandni:
Your http://www.leximindia.com/infovalidation.html
form is perfect.

copy your existing php form here and someone will take a look and advise you. (put xxxx@xxxx.com in your email address before you post the php)

chandni
04-29-2006, 11:24 AM
thanks for you reply but i am confused.. where do i take the php from...
many thanks
chandni

nick1346
04-29-2006, 12:04 PM
Hi There,

You can find the php file in your public html folder in your ftp manager. To get that open blue voda, click on tools, ftp manger,go into your public html folder and you'll find it there as contactus1.php, save that to your hard drive then cut and paste that into a post here.
Nick

navaldesign
04-29-2006, 12:12 PM
If i understand well, chandni has not yet created and uploaded a php script. He's asking for one, i'm i correct?

chandni
04-29-2006, 12:23 PM
yes navaldesign, the php script to validate is what i requested for. can u please help me with the php script. and where should i add this php script.

thanks
chandni

navaldesign
04-29-2006, 12:52 PM
Ok, i'll preapare a script for you. When i'll have it ready, you must upload it to your site using BlueFTP. I'll post back for you.

chandni
04-29-2006, 01:04 PM
i shall wait for ur script, many thanks navaldesign u have been very helpful

chandni

navaldesign
04-29-2006, 01:20 PM
Sorry, just found out that your fields are not named correctly. They are named T1, T2 etc. Please give your fields real names, like "Name", Surname" etc. and then republish and let me know

chandni
04-29-2006, 01:37 PM
i am sorry about that navaldesign i have republised the page with real names...
many thanks
chandni

navaldesign
04-29-2006, 01:45 PM
Ok, i'll let you know

navaldesign
04-29-2006, 04:19 PM
Hi,

here it goes:

<?php
// Receiving variables
@$Tittle = addslashes($_POST['Tittle']);
@$Name = addslashes($_POST['Name']);
@$Surname = addslashes($_POST['Surname']);
@$Companyname = addslashes($_POST['Companyname']);
@$Address1 = addslashes($_POST['Address1']);
@$state = addslashes($_POST['state']);
@$Address2 = addslashes($_POST['Address2']);
@$City = addslashes($_POST['City']);
@$country = addslashes($_POST['country']);
@$pin = addslashes($_POST['pin']);
@$email = addslashes($_POST['email']);
@$telephone = addslashes($_POST['telephone']);
// Validation
if (strlen($Name) == 0 )
{
header("Location: infovalidation.html");
exit;
}
if (strlen($Surname) == 0 )
{
header("Location: infovalidation.html");
exit;
}
if (strlen($Companyname) == 0 )
{
header("Location: infovalidation.html");
exit;
}
if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email))
{
header("Location: infovalidation.html");
exit;
}
if (strlen($email) == 0 )
{
header("Location: infovalidation.html");
exit;
}
if (strlen($telephone) == 0 )
{
header("Location: infovalidation.html");
exit;
}
// Find Server date and Time
$date = date("l jS F Y, g:i A");
// Find Browser and IPaddress
$browser =$_SERVER['HTTP_USER_AGENT'];
$ip = $_SERVER['REMOTE_ADDR'];

//Sending Email to form owner
$pfw_header = "From: $email\n"
. "Reply-To: $email\n";
$pfw_subject = "Info Submited by our Web Information Request Form";
$pfw_email_to = "youremail@leximindia.com";

$pfw_message = "----------------------------------------------------\n"
. "Tittle: $Tittle\n"
. "Name: $Name\n"
. "Surname: $Surname\n"
. "Companyname: $Companyname\n"
. "Address1: $Address1\n"
. "Address2: $Address2\n"
. "City: $City\n"
. "state: $state\n"
. "country: $country\n"
. "pin: $pin\n"
. "email: $email\n"
. "telephone: $telephone\n"
. "----------------------------------------------------\n"
. "Received on : $date\n"
. "Browser : $browser\n"
. "IP address : $ip\n"
. "----------------------------------------------------\n";
*****($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;
header("Location: thankyou_page.html");
?>


1. Copy the code and paste it in Notepad. Change the email adress to be your own email address in your Vodahost account.
2. Create a "thankyou" page in BV. Save it as "thankyou_page". Publish it.
3. Go to "Save as", choose "File type", select "All files", and save it as "contactus1.php". Upload it on the server using Blue FTP. DO NOT PASTE IT IN ANY BV PAGE.
4. If in the future you need to create different error pages for every error, just change this line:
header("Location: infovalidation.html");
after every field validation.
5. You may want to avoid your visitors having to press the browser "Back" button. You can insert a "Back button" directly in your "infovalidation" page by either inserting an Advanced Button (BV,>Insert>Form>Advanced Button, make it "On click", give it action "Go to the previous Page", OR you can insert an HTML box in your page, and paste in it the following code:
<FORM>
<input type="button" class="but" value="< BACK TO THE FORM " onclick=history.go(-1)>
</FORM>

Let me know if everything has worked out ok.

navaldesign
04-29-2006, 04:22 PM
Forgot: change the encoding of your form in "multipart / form data" save it and republish it.

chandni
04-29-2006, 06:06 PM
ur a genuis navaldesign thank you so much.....
regards
chandni