Jump to content

PHP form validation help needed


BlackSmith

Recommended Posts

<?php

if(isset($_POST['Submit']))

{

//Email information

$to = "email@email.net";

$subject = "New Services Web Application";

$from = "email@anotheremail.net";

$headers = "From: $from";

 

 

//Email content from the signup.php form

$regperiod = $_POST['regperiod'];

$domain_name = $_POST['domain_name'];

$topleveldomain = $_POST['topleveldomain'];

$organization = $_POST['organization'];

$id_number = $_POST['id_number'];

$first_name = $_POST['first_name'];

$last_name = $_POST['last_name'];

$email = $_POST['email'];

$contact_number = $_POST['contact_number'];

$fax_number = $_POST['fax_number'];

$address = $_POST['address'];

$city = $_POST['city'];

$postalcode = $_POST['postalcode'];

$province = $_POST['province'];

$other_province = $_POST['other_province'];

$country = $_POST['country'];

$password1 = $_POST['password1'];

$password2 = $_POST['password2'];

 

 

//Message content

$message1 = "Good day, please assist in the processing of the following new application  \n

Registration period: $regperiod \n

Domain name: www.$domain_name.$topleveldomain \n

Organization: $organization \n

Id Number: $id_number \n

First Name: $first_name \n

Last Name: $last_name \n

Email Address: $email \n

Contact Number: $contact_number \n

Fax Number: $fax_number \n

Address: $address \n

City: $city \n

Postal Code: $postalcode \n

Province: $province \n

Other Province: $other_province \n

Country: $country \n

Password: $password1 \n

Confirn Password: $password2";

 

 

 

 

mail($to,$subject,$headers,$message1);

echo "Mail Sent. Click <a href='index.php'>here</a> to return to home page";

}

else

{

echo "Sorry there was a problem delivering your email please try again";

}

//End of new applications script

?>

 

 

 

I need some serious help with the validation of the script above - as you can see, the user's input is not being validated. Please assist with either PHP or JavaScript validation.

 

I will post you a box of chocolates or Mint flavored gums...

 

 

Link to comment
Share on other sites

  • 2 weeks later...

In total (email info and email content) you have 22 variables I think. Not sure how many you need to validate but just use a for loop to iterate each element and perform whatever validation you need. First of course you need to put all your variables that require validation into a numerically indexed array. Then use the for loop to iterate through each item and perform whatever validation you require. The array would look something like this:

$array = array("$to", "$subject", "$from" ....etc)

Then use a for loop. The second expression which is evaluated should test against the number of items to be checked. So for example, if you have 5 items to validate then your for loop should look something like this:

$item = 5;
for($i =0; $i<=$item;$i++)
{
    $array[$i]; //this is how to retrieve the item to be checked in the array.  
//perform validation here.
}

That should solve most if not all of your problems. Hope this helped.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.