Name: BigShow Date: April 17, 2008 at 06:43:30 Pacific Subject: form validation, multiple fields OS: xp CPU/Ram: pentium Model/Manufacturer: dell
Comment:
Hey guys, I have created an email form with about 20 fields. I need to make sure that ..
1. they are filled in
2. they have correct info, (phone=int, email has a @)
3. they are free fron sql injection.
I did it the long way for the first two but I know that there is a way to run a loop to check them, I think I can set a variable to " " nad then just check all the fields to that, I cannot get it to work though. Also, I ran across some predefined functions on the W3C website for sanitizing email but they dont want to cooperate.
I would create a function to do all of the validations, then pass each variable to the function in turn passing a paramter to indicate the type of validatin to occure (emptuy, email, phone, etc). You also need to plan out in what order the validatins will take place. For example, if the email address is a required field then you wouldn't want to give the user an erro message such as
"Email addres is required. Email address is not valid"
Do you want to show ALL errors that occur or stop on the first? You state this is an email form. But, if you are going to store the information in a DB then you need to do different things for the different outputs. When "writing" the text to the email I'd probably use htmlentities(). When writing to a MySQL database youwill want to use mysql_real_escape_strings().
In another post you also stated that some of this info would be used to save images to a custom folder. IIn that case you would need to replace characters that aren't supported for the file system. I'm sure there's a command for that, but I don't know of it.
But, to be honest, for me to give any real constructive advice I would need to know a little more about how you are using the data. For example a statement such as
"The data will first be used to construct an email. The images will be saved to the server and links to those images will be included in the email. Once the email is sent, the text of the email will be saved to the DB for logging purposes"
A user will fill out this form to become a member of the sight. 19 fields are general fields, name, email, location,ect.., there are also seven image fields for images, these images will be used by the owner of the website to construct the users profile page. It is not required to send 7 images, just 2. The other 5 are optional.
When the user submits the form, the first thing that happens is all the fields are checked to make sure they are completed.
After that I want to create a directory which will be named a combo of probably the users email and phonenumber to make it original.
Then, all the info except the images (obviously) will be written to a file and stored in that directory. The the images will have the users email added to the name and they will also be stored in the directory.
I have a lot to check after I actually get this thing to work, like making sure there are no duplicate directories or the pics inside the directory will be different.
Thats where I am starting. I need to make sure that the script sets the chmod to 777 to make sure it is accesible. This is where it gets hairy, people talk about security and using ftp to do the file uploading part.
Michael I created the form, maybe this will help a little, I will start the script, I am more concerned with a way to create a directory, I can figure the rest out. If you have any ideas on the best route to go that would help.
I don't know why you wouldn't want to use a database when you are going to be creating user accounts.
To create a folder you would use mkdir(). I didn't know this offhand - I just did a Google search. Take a look at the manual for that command and read through the User Contributed Notes at the bottom. There is a lot of good information there.
The site is in beta right and there is only a landing page, we want to get a few people signed up the nwe will start the database, right now its just too early, thats what they are saying anyways, the file thing is temporary
Hey Michael, I did the javascript and html, I have not tested it yet but will tommorow. I am working on the php.I am going to post the code below. Basically I took all the text info and wrote it to a file. Then I want to create a directory using phpftp and move that file and the pictures into the directory. I can use the move_file function, but first I will use the isset() function to make sure it is not empty then I will move it. I have got a head of myself. Can you take a look and help me figure out the uploading files part.
// set up basic connection $conn_id = ftp_connect($ftp_server);
// login with username and password $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to create the directory $dir if (ftp_mkdir($conn_id, $dir)) { // make sure the image file is set then move it if (isset($business_logo)) { move_uploaded_file ($_FILES[$business_logo] ['tmp_name'], "../uploads/{$_FILES['uploadFile'] ['name']}") } else { echo "There was a problem while creating $dir\n"; }
// close the connection ftp_close($conn_id);
?>
you can go to iwebexp.com and look at the source, that is the html and javascript i used.
I don't understand why you are wanting to use FTP? Are you saving the files to a different server from the server your site is running on? If not, then there are more efficient methods. Just look for a file upload tutorial.
As for your code. I thik all those fwrites is a bit overkill. Just add all the data to a single variable and write to the file once:
Also, all of your "$stringData" lines have a typo. Either you need to put a period between the variable and the string with the newline character, or you need to include the varialbe inside the string as I did above.
What I am running into is the first image is fine but then when it stores the second image it adds it on to the first and adds it, for example if the first image was $first_img.gif nad the second was $second_img.gif and the third was $third_img.gif then in my profile file it would look like
I need to find another way to make sure the variabls are set and then move all them at once, keep in mind it is only required to submit 2 images, not all 7.
I have the form processing without any problems, but i need to fix two bugs tha are not stopping the form but I no are there.
One, when my txt file gets creates the "\n" is not breaking the lines. so it is coming out in a straight line.
In the html i have a select filed with multiple select turned on, you can choose two selections. The validation works fine and I pass it to the php for to process but I cannot get it to show the values and in the txt file it writes it as aray. How do i use php to break down the array and assign seperate values.
For issue #2, it is an array so you access the values like any other array. $_POST['field_name'][0] = the 1st value $_POST['field_name'][1] = the 2nd value
The information on Computing.Net is the opinions of its users. Such
opinions may not be accurate and they are to be used at your own risk.
Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE