...

View Full Version : Validating my form



rockonmetal
08-28-2007, 02:29 AM
Ok, I have tried 4 different forums today and I have not got a single response... I hope someone can help me here... I really can't work with tutorial's unless it tells what each feature does and how to edit it or it displays the correct code, but I would rather you please just make a validation for this form using php when the submit button is pressed.

<form action="uploader.php" method="post" enctype="multipart/data">
<input type="hidden" name="3p42r3ad3a4than32" value="329r8g" />
<div class="pureadd">
<br>
<br>Your Name:
<br><input type="text" name="Name" class="input" />
<br>Your Email:
<br><input type="text" name="Email" class="input"/>
<br>
<script type="text/javascript">
var d = new Date()
document.write("<input type='hidden' value='"+Date()+"' name='time' />")
</script>
<br>
<br>Agree To Terms of Service
<br><input type="checkbox" name="TermsOfService" value="Agreed" /> Yes I Agree To the Terms of Service
<br>

File Description:
<br>
<textarea rows="5" cols="40" name="description" id="maxcharfield" onKeyDown="textCounter(this,'progressbar1',200)" onKeyUp="textCounter(this,'progressbar1',200)" onFocus="textCounter(this,'progressbar1',200)" class="textarea"></textarea><br />
<div id="progressbar1" class="progress"></div>

<input type="submit" class="input">


</div>
</form>
THANKS!

Erindesign
08-28-2007, 02:53 AM
Now by validating, do you mean to see if everything is properly filled out and whatnot?

rockonmetal
08-28-2007, 02:54 AM
Ok, by validating i mean to see whether if all the form inputs are properly filled out do you think you could write some code that could when the user clicks the submit button check the code before it sends it to make sure everything is filled out, and that there is a valid email address *or as close as you can get*

Thanks and please say something if your going to help or just put the code up, *THANKS!!!!!!!!!!!!!!!!!*

Erindesign
08-28-2007, 04:06 AM
I don't understand how this is an uploader script? or is that just the name you gave the action?

rockonmetal
08-28-2007, 04:14 AM
on my form, the next page (uploader.php) is an file uploader which works and does not need any attention because it works PERFECTLY! Please, if someone could give/make me the code for this form so that:
1. No fields are left blank
2. That the email input has a valid email address or can be a email address...
3. And that when the SUBMIT button is pressed, the code will validate form based on the 3 things above if it isn't valid then have the form say so...
Thats all I need... Thanks

meth
08-28-2007, 07:05 AM
If you going to have this form submit to uploader.php, then that is the file which will be doing the validation, not this one.

Unless of course you want javascript validation; in this case you're posting in the wrong forum.

rockonmetal
08-28-2007, 01:08 PM
Ok then what do I put on uploader.php ... because I really don't have time wasted on silly questions *sorry but 10 days till release of site*

rafiki
08-28-2007, 01:53 PM
$err = '';
if (empty($_POST['data'])) {
$err = '1'
}//do that for as many fields as you like.
if() { // look up ilovejackdaniels.com for a regex email validator
}
if ($err == '') { // or use if ($err != '' or $err == 1 etc..
//upload
}else{
die(form field left empty...);
}

rockonmetal
08-28-2007, 01:57 PM
THANK YOU!! now i'm going to go test it!!!!!!!!!!!!!

YEAH!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!! *idk if it works yet i'm just glad someone responded...*

rafiki
08-28-2007, 02:05 PM
dont forget to set $err to 1 or so mething if the email validation fails, forgot that sorry

rockonmetal
08-28-2007, 02:26 PM
? Oh, Idk why but it won't work... heres the code to uploader.php...



<?php $err = '';
if (empty($_POST['name'])) {
$err = '1'
}
if() { function check_email_address($email) {
(!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { return false; } $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i <

sizeof($local_array); $i++) {
if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if

(!ereg("^\[?[0-9\.]+\]?$", $email_array[1]))
{domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; } for ($i = 0; $i < sizeof($domain_array); $i++) { if

(!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true;}

}
if ($err == '') {if ($err != '' or $err == 1 etc..
else{
die(form field left empty...);
}
?>
<?php
$filename = 'data.html';
$input1 = $_SERVER['REMOTE_ADDR'];
$input2 = $_POST["Name"];
$input3 = $_POST["Email"];
$input4 = $_POST["time"];
$input5 = $_POST["3p42r3ad3a4than32"];
$input6 = $_POST["Description"];
$data = "<table border='1'><tr><td>User IP Address:</td><td>$input1</td></tr><tr><td>Name:</td><td>$input2</td></tr><tr><td>Email

Address:<td>$input3</td></tr><tr><td>Date Submitted:</td><td>$input4</td></tr><tr><td>Description</td><td><textarea cols='50'

rows='5'>$input6</textarea></td></tr></table>";


if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}

// Write $somecontent to our opened file.
if (fwrite($handle, $data) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}

echo "Success your information has been submitted! Now please submit your files...";

fclose($handle);

} else {
echo "The file $filename is not writable";
}

?>
<?php
$upload_dir = "submitions/";
$num_files = 2;
//the file size in bytes.
$size_bytes =20480000; //51200 bytes = 50KB.
//Extensions you want files uploaded limited to.
$limitedext = array(".gif",".jpg",".jpeg",".png",".bmp",".mov",".mpg",".mpeg");


//check if the directory exists or not.
if (!is_dir("$upload_dir")) {
die ("Error: The directory <b>($upload_dir)</b> doesn't exist because we are in the process of the weekly upload.");
}
//check if the directory is writable.
if (!is_writeable("$upload_dir")){
die ("Error: The directory <b>($upload_dir)</b> is NOT writable, Please click contact and then contact technical support to tell them this problem.");
}


//if the form has been submitted, then do the upload process
//infact, if you clicked on (Upload Now!) button.
if (isset($_POST['upload_form'])){

echo "<h3>Upload results:</h3>";

//do a loop for uploading files based on ($num_files) number of files.
for ($i = 1; $i <= $num_files; $i++) {

//define variables to hold the values.
$new_file = $_FILES['file'.$i];
$file_name = $new_file['name'];
//to remove spaces from file name we have to replace it with "_".
$file_name = str_replace(' ', '_', $file_name);
$file_tmp = $new_file['tmp_name'];
$file_size = $new_file['size'];

#-----------------------------------------------------------#
# this code will check if the files was selected or not. #
#-----------------------------------------------------------#

if (!is_uploaded_file($file_tmp)) {
//print error message and file number.
echo "File $i: Not selected.<br>";
}else{

$ext = strrchr($file_name,'.');
if (!in_array(strtolower($ext),$limitedext)) {
echo "File $i: ($file_name) Wrong file extension. <br>";
}else{


if ($file_size > $size_bytes){
echo "File $i: ($file_name) Faild to upload. File must be <b>". $size_bytes / 1024 ."</b> KB. <br>";
}else{


if(file_exists($upload_dir.$file_name)){
echo "File $i: ($file_name) already exists.<br>";
}else{

if (move_uploaded_file($file_tmp,$upload_dir.$file_name)) {
echo "File $i: ($file_name) Uploaded.<br>";
}else{
echo "File $i: Faild to upload.<br>";
}#end of (move_uploaded_file).

}#end of (file_exists).

}#end of (file_size).

}#end of (limitedext).

}#end of (!is_uploaded_file).

}#end of (for loop).
# print back button.
echo "<a href=\"$_SERVER[PHP_SELF]\">back</a>";
////////////////////////////////////////////////////////////////////////////////
//else if the form didn't submitted then show it.
}else{
echo " <h3>Select files to upload!.</h3>
Max file size = ". $size_bytes / 1024 ." KB";
echo " <form method=\"post\" action=\"$_SERVER[PHP_SELF]\" enctype=\"multipart/form-data\">";
// show the file input field based on($num_files).
for ($i = 1; $i <= $num_files; $i++) {
echo "File $i: <input type=\"file\" name=\"file". $i ."\"><br>";
}
echo " <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$size_bytes\">
<input type=\"submit\" name=\"upload_form\" value=\"Upload Now!\">
</form>";
}
?>
</body>
</html>

I have no idea whats going on, BTW i only wrote this part nothing else...

$filename = 'data1.html';
$input1 = $_SERVER['REMOTE_ADDR'];
$input2 = $_POST["Name"];
$input3 = $_POST["Email"];
$input4 = $_POST["time"];
$input5 = $_POST["3p42r3ad3a4than32"];
$input6 = $_POST["Description"];
$data = "<table border='1'><tr><td>User IP Address:</td><td>$input1</td></tr><tr><td>Name:</td><td>$input2</td></tr><tr><td>Email
Address:<td>$input3</td></tr><tr><td>Date Submitted:</td><td>$input4</td></tr><tr><td>Description</td><td><textarea cols='50'

rows='5'>$input6</textarea></td></tr></table>";

rafiki
08-28-2007, 02:34 PM
<?php $err = '';
if (empty($_POST['name'])) {
$err = '1'
}
if(!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { $err = 1; } $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i <

sizeof($local_array); $i++) {
if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { $err = 1; } } if

(!ereg("^\[?[0-9\.]+\]?$", $email_array[1]))
{domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { $err = 1; } for ($i = 0; $i < sizeof($domain_array); $i++) { if

(!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { $err = 1; } } } continue;}

}
if ($err == '') {

$filename = 'data.html';
$input1 = $_SERVER['REMOTE_ADDR'];
$input2 = $_POST["Name"];
$input3 = $_POST["Email"];
$input4 = $_POST["time"];
$input5 = $_POST["3p42r3ad3a4than32"];
$input6 = $_POST["Description"];
$data = "<table border='1'><tr><td>User IP Address:</td><td>$input1</td></tr><tr><td>Name:</td><td>$input2</td></tr><tr><td>Email

Address:<td>$input3</td></tr><tr><td>Date Submitted:</td><td>$input4</td></tr><tr><td>Description</td><td><textarea cols='50'

rows='5'>$input6</textarea></td></tr></table>";


if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}

// Write $somecontent to our opened file.
if (fwrite($handle, $data) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}

echo "Success your information has been submitted! Now please submit your files...";

fclose($handle);

} else {
echo "The file $filename is not writable";
}

?>
<?php
$upload_dir = "submitions/";
$num_files = 2;
//the file size in bytes.
$size_bytes =20480000; //51200 bytes = 50KB.
//Extensions you want files uploaded limited to.
$limitedext = array(".gif",".jpg",".jpeg",".png",".bmp",".mov",".mpg",".mpeg");


//check if the directory exists or not.
if (!is_dir("$upload_dir")) {
die ("Error: The directory <b>($upload_dir)</b> doesn't exist because we are in the process of the weekly upload.");
}
//check if the directory is writable.
if (!is_writeable("$upload_dir")){
die ("Error: The directory <b>($upload_dir)</b> is NOT writable, Please click contact and then contact technical support to tell them this problem.");
}


//if the form has been submitted, then do the upload process
//infact, if you clicked on (Upload Now!) button.
if (isset($_POST['upload_form'])){

echo "<h3>Upload results:</h3>";

//do a loop for uploading files based on ($num_files) number of files.
for ($i = 1; $i <= $num_files; $i++) {

//define variables to hold the values.
$new_file = $_FILES['file'.$i];
$file_name = $new_file['name'];
//to remove spaces from file name we have to replace it with "_".
$file_name = str_replace(' ', '_', $file_name);
$file_tmp = $new_file['tmp_name'];
$file_size = $new_file['size'];

#-----------------------------------------------------------#
# this code will check if the files was selected or not. #
#-----------------------------------------------------------#

if (!is_uploaded_file($file_tmp)) {
//print error message and file number.
echo "File $i: Not selected.<br>";
}else{

$ext = strrchr($file_name,'.');
if (!in_array(strtolower($ext),$limitedext)) {
echo "File $i: ($file_name) Wrong file extension. <br>";
}else{


if ($file_size > $size_bytes){
echo "File $i: ($file_name) Faild to upload. File must be <b>". $size_bytes / 1024 ."</b> KB. <br>";
}else{


if(file_exists($upload_dir.$file_name)){
echo "File $i: ($file_name) already exists.<br>";
}else{

if (move_uploaded_file($file_tmp,$upload_dir.$file_name)) {
echo "File $i: ($file_name) Uploaded.<br>";
}else{
echo "File $i: Faild to upload.<br>";
}#end of (move_uploaded_file).

}#end of (file_exists).

}#end of (file_size).

}#end of (limitedext).

}#end of (!is_uploaded_file).

}#end of (for loop).
# print back button.
echo "<a href=\"$_SERVER[PHP_SELF]\">back</a>";
////////////////////////////////////////////////////////////////////////////////
//else if the form didn't submitted then show it.
}else{
echo " <h3>Select files to upload!.</h3>
Max file size = ". $size_bytes / 1024 ." KB";
echo " <form method=\"post\" action=\"$_SERVER[PHP_SELF]\" enctype=\"multipart/form-data\">";
// show the file input field based on($num_files).
for ($i = 1; $i <= $num_files; $i++) {
echo "File $i: <input type=\"file\" name=\"file". $i ."\"><br>";
}
echo " <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$size_bytes\">
<input type=\"submit\" name=\"upload_form\" value=\"Upload Now!\">
</form>";
}
}
else{
die("Errors");
}
try that

rockonmetal
08-28-2007, 03:27 PM
Uh I don't know why but I ain't getting anything on uploader.php

rafiki
08-28-2007, 03:37 PM
have you got a link to it?

rockonmetal
08-28-2007, 03:40 PM
I don't have a link to it yet because well, its under developement

rafiki
08-28-2007, 04:11 PM
well i used the same code, fixed a couple errors and modified it to show a form instead of showing a message which says "errors" after i submit the form it takes me back to the form i dont know why heres code if you want to play around with it.

<?php
$err = '';
if (empty($_POST['name'])) {
$err = '1';
}
$email = $_POST['email'];
function check_email_address($email) {
// First, we check that there's one @ symbol, and that the lengths are right
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
// Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
return false;
}
// Split it into sections to make life easier
$email_array = explode("@", $email);
$local_array = explode(".", $email_array[0]);
for ($i = 0; $i < sizeof($local_array); $i++) {
if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
return false;
}
}
if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
$domain_array = explode(".", $email_array[1]);
if (sizeof($domain_array) < 2) {
return false; // Not enough parts to domain
}
for ($i = 0; $i < sizeof($domain_array); $i++) {
if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
return false;
}
}
}
return true;
}
if(!check_email_address($email)){
$err = 1;
}
if ($err == '') {

$filename = 'data.html';
$input1 = $_SERVER['REMOTE_ADDR'];
$input2 = $_POST["Name"];
$input3 = $_POST["Email"];
$input4 = $_POST["time"];
$input5 = $_POST["3p42r3ad3a4than32"];
$input6 = $_POST["Description"];
$data = "<table border='1'><tr><td>User IP Address:</td><td>$input1</td></tr><tr><td>Name:</td><td>$input2</td></tr><tr><td>Email

Address:<td>$input3</td></tr><tr><td>Date Submitted:</td><td>$input4</td></tr><tr><td>Description</td><td><textarea cols='50'

rows='5'>$input6</textarea></td></tr></table>";


if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}

// Write $somecontent to our opened file.
if (fwrite($handle, $data) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}

echo "Success your information has been submitted! Now please submit your files...";

fclose($handle);

} else {
echo "The file $filename is not writable";
}

?>
<?php
$upload_dir = "submitions/";
$num_files = 2;
//the file size in bytes.
$size_bytes =20480000; //51200 bytes = 50KB.
//Extensions you want files uploaded limited to.
$limitedext = array(".gif",".jpg",".jpeg",".png",".bmp",".mov",".mpg",".mpeg");


//check if the directory exists or not.
if (!is_dir("$upload_dir")) {
die ("Error: The directory <b>($upload_dir)</b> doesn't exist because we are in the process of the weekly upload.");
}
//check if the directory is writable.
if (!is_writeable("$upload_dir")){
die ("Error: The directory <b>($upload_dir)</b> is NOT writable, Please click contact and then contact technical support to tell them this problem.");
}


//if the form has been submitted, then do the upload process
//infact, if you clicked on (Upload Now!) button.
if (isset($_POST['upload_form'])){

echo "<h3>Upload results:</h3>";

//do a loop for uploading files based on ($num_files) number of files.
for ($i = 1; $i <= $num_files; $i++) {

//define variables to hold the values.
$new_file = $_FILES['file'.$i];
$file_name = $new_file['name'];
//to remove spaces from file name we have to replace it with "_".
$file_name = str_replace(' ', '_', $file_name);
$file_tmp = $new_file['tmp_name'];
$file_size = $new_file['size'];

#-----------------------------------------------------------#
# this code will check if the files was selected or not. #
#-----------------------------------------------------------#

if (!is_uploaded_file($file_tmp)) {
//print error message and file number.
echo "File $i: Not selected.<br>";
}else{

$ext = strrchr($file_name,'.');
if (!in_array(strtolower($ext),$limitedext)) {
echo "File $i: ($file_name) Wrong file extension. <br>";
}else{


if ($file_size > $size_bytes){
echo "File $i: ($file_name) Faild to upload. File must be <b>". $size_bytes / 1024 ."</b> KB. <br>";
}else{


if(file_exists($upload_dir.$file_name)){
echo "File $i: ($file_name) already exists.<br>";
}else{

if (move_uploaded_file($file_tmp,$upload_dir.$file_name)) {
echo "File $i: ($file_name) Uploaded.<br>";
}else{
echo "File $i: Faild to upload.<br>";
}#end of (move_uploaded_file).

}#end of (file_exists).

}#end of (file_size).

}#end of (limitedext).

}#end of (!is_uploaded_file).

}#end of (for loop).
# print back button.
echo "<a href=\"$_SERVER[PHP_SELF]\">back</a>";
////////////////////////////////////////////////////////////////////////////////
//else if the form didn't submitted then show it.
}else{
echo " <h3>Select files to upload!.</h3>
Max file size = ". $size_bytes / 1024 ." KB";
echo " <form method=\"post\" action=\"$_SERVER[PHP_SELF]\" enctype=\"multipart/form-data\">";
// show the file input field based on($num_files).
for ($i = 1; $i <= $num_files; $i++) {
echo "File $i: <input type=\"file\" name=\"file". $i ."\"><br>";
}
echo " <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$size_bytes\">
<input type=\"submit\" name=\"upload_form\" value=\"Upload Now!\">
</form>";
}
}
else{
?>
<form action="test.php" method="POST" enctype="text/plain" >
<input type="text" name="name" />
<input type="text" name="email" />
<input type="submit" value="submit" />
<input type="reset" value="reset form" />
</form>
<?php
}

?>

rockonmetal
08-28-2007, 04:46 PM
Ok, i got something different this time!


Ok, hold on a second I saw you did something different...

rockonmetal
08-28-2007, 05:02 PM
I am not getting any difference with anything no validation message alert

rafiki
08-28-2007, 05:21 PM
can you write and understand php?

rockonmetal
08-28-2007, 05:28 PM
The only thing I know how to do is use variables in echo...

$name = "Duh"; echo "$name,";
but I can understand some scripts if they have some notes in them tell what some parts do...

I mainly learned html, javascript, and css by seeing the correct code and then messing with...

rockonmetal
08-28-2007, 05:56 PM
All I'm looking for is for someone to write the code to validate this form so no fields are left blank and that the email input actually has a either valid or possibly valid email address. Please I don't really know any php, don't speak in php because i don't know php. All I need is the code and then I'm gone for good... thanks!

rockonmetal
08-28-2007, 06:13 PM
i have just got my first if statemet
here it is

<?php
$a = '4';
$b = '5';
if ($a > $b)
echo "A is bigger than b.";
else{
echo "A is smaller than b.";
}
?>
Now i'm thinking...
If i could do something like this

<?php
$input1 = $_POST["Name"];
$b = '';
if ($input1 = $b)
echo "Invalid input...";

else{
echo "Sorry but that input is not valid...";
}
?>

I got one question...
So, can the actual file write actually happen on a different page... example below:

Page 1. User Info Form *when user clicks submit go to validate.php*
Page 2. Validation *if form is valid then go to uploader.php*
Page 3. Upload and write data to file *I got that part...*
I was just wondering can variables be in effect till user exits browser?

rafiki
08-28-2007, 06:22 PM
why would some one do a job for free with no clue what the sites for. okay its still a small but you could offer a small reward.

rockonmetal
08-28-2007, 06:27 PM
Idk, I belong to dynamic drive's forum to and people do it all the time...
BTW its for a site called Pureadd. and no i have no rewards because I am so tight with time and I have to probably pay someone to design a flash video/audio player... great fun...
So please if you could help that would be great if your not going to, than please say so...

rafiki
08-28-2007, 06:52 PM
<?php
$input1 = $_POST["Name"];
$b = '';
if ($input1 = $b)
echo "Invalid input...";
//missing the closing curly brace..
}else{
echo "Sorry but that input is not valid..."; // how can you get correct input
//if they both echo bad input?
}
?>

I got one question...
So, can the actual file write actually happen on a different page... example below:

Page 1. User Info Form *when user clicks submit go to validate.php*
Page 2. Validation *if form is valid then go to uploader.php*
Page 3. Upload and write data to file *I got that part...*
I was just wondering can variables be in effect till user exits browser?
yes its called a session
you call the session with session_start() at the top of every page
you set session variables like $_SESSION['varname'] = myvar;
session variables are stored in the session array accessed threw $_SESSION['varname'] at all times. learn more about sessions at http://www.php.net/manual/en/ref.session.php

rockonmetal
08-28-2007, 07:05 PM
Its very easy...

rockonmetal
08-28-2007, 07:18 PM
I will post the php validation code I can't believe its really this easy...

rockonmetal
08-28-2007, 07:52 PM
Ok, I got one problem...
I have no idea how to get something:
In order to make sure to see someone has entered in a certain amount of characters say "100" then I wanted to to preform a string action...

strlen('$input7')
And then turn in into a variable thats all i ask...

rafiki
08-28-2007, 08:26 PM
$len = strlen($input7);
if ($len <= 100) {
echo "error: input7 requires more chars";
}

rockonmetal
08-28-2007, 08:44 PM
k, i'll try it out...

Erindesign
08-29-2007, 01:56 AM
how about u do something simple and not worry about retarded sh*t?



if($field1=='' || $field2=='' || $field3=='') etc etc if you need more without making 1000 if statements.{
echo("error");
}
else{
echo("success");
}


under success you can put javascript or w/e you feel like.

rafiki
08-29-2007, 11:36 AM
define retarted ****? and yeah you can you can even close php to make it si mpler to put html or jscript.

aedrin
08-29-2007, 04:59 PM
define retarted ****?

Spaghetti code with multiple sections of code copied and pasted.

I think the starter of this topic needs to realize that if you want work done for you, pay someone to do it.

Otherwise learn how to do it yourself.

http://www.google.com/search?q=php+form+validation (2.2million results)

rafiki
08-29-2007, 05:02 PM
Spaghetti code with multiple sections of code copied and pasted.

I think the starter of this topic needs to realize that if you want work done for you, pay someone to do it.

Otherwise learn how to do it yourself.

http://www.google.com/search?q=php+form+validation (2.2million results)
which i said in a post a few posts ago

aedrin
08-29-2007, 05:07 PM
You should've probably suggested this before you spent a dozen posts trying to explain PHP to someone who does not know PHP ;)

rockonmetal
08-30-2007, 06:15 PM
Lol, ok here is the code I got one problem... I got a bunch of if statements, but i don't got time for your stupid **** suggestions so please just tell me whats WRONG with my code, please don't say "YOU SHOULDN'T/Can't DO THAT!" because it works, so please just tell me whats wrong with this:

<html>
<body>
<?php
$input2 = $_POST["Name"];
$input3 = $_POST["Email"];
$input4 = $_POST["time"];
$input5 = $_POST["TermsOfService"];
$input6 = $_POST["3p42r3ad3a4than32"];
$input7 = $_POST["Title"];
$input8 = $_POST["Description"];
$input9 = $_POST["file1"];
$input10 = $_POST["file2"];
$empty = '';
$agree = 'Agreed';
$a = '329r8g';

?>
<?php
$c = '1';
$d = '0';
$valid = '5';
if ($empty == $input2) {
echo "Your Name cannot be blank.<br>";
} else {
++$d;
}

if ($empty == $input3) {
echo "Your EmailAddress cannot be blank.<br>";
} else {
++$d;
}
if ($empty == $input4) {
echo "Make sure your clock is set to the correct date, we record dates so we can know exactly when you submitted your files...<br>";
} else {
++$d;
}
if ($empty == $input5) {
echo "You must agree to the Terms Of Service.<br>";
} else {
++$d;
}
if ($empty == $input6) {
echo "There is an error with our form we are sorry for this problem we will fix it tomorrow.<br>";
} else {
++$d;
}
if ($d == $valid){
$upload_dir = "submitions/";
$num_files = 2;
//the file size in bytes.
$size_bytes =20480000; //51200 bytes = 50KB.
//Extensions you want files uploaded limited to.
$limitedext = array(".gif",".jpg",".jpeg",".png",".bmp",".mov",".mpg",".mpeg");


//check if the directory exists or not.
if (!is_dir("$upload_dir")) {
die ("Error: The directory <b>($upload_dir)</b> doesn't exist because we are in the process of the weekly upload.");
}
//check if the directory is writable.
if (!is_writeable("$upload_dir")){
die ("Error: The directory <b>($upload_dir)</b> is NOT writable, Please click contact and then contact technical support to tell them this problem.");
}


//if the form has been submitted, then do the upload process
//infact, if you clicked on (Upload Now!) button.
if (isset($_POST['upload_form'])){

echo "<h3>Upload results:</h3>";

//do a loop for uploading files based on ($num_files) number of files.
for ($i = 1; $i <= $num_files; $i++) {

//define variables to hold the values.
$new_file = $_FILES['file'.$i];
$file_name = $new_file['name'];
//to remove spaces from file name we have to replace it with "_".
$file_name = str_replace(' ', '_', $file_name);
$file_tmp = $new_file['tmp_name'];
$file_size = $new_file['size'];

#-----------------------------------------------------------#
# this code will check if the files was selected or not. #
#-----------------------------------------------------------#

if (!is_uploaded_file($file_tmp)) {
//print error message and file number.
echo "File $i: Not selected.<br>";
}else{

$ext = strrchr($file_name,'.');
if (!in_array(strtolower($ext),$limitedext)) {
echo "File $i: ($file_name) Wrong file extension. <br>";
}else{


if ($file_size > $size_bytes){
echo "File $i: ($file_name) Faild to upload. File must be <b>". $size_bytes / 1024 ."</b> KB. <br>";
}else{


if(file_exists($upload_dir.$file_name)){
echo "File $i: ($file_name) already exists.<br>";
}else{

if (move_uploaded_file($file_tmp,$upload_dir.$file_name)) {
echo "File $i: ($file_name) Uploaded.<br>";
}else{
echo "File $i: Faild to upload.<br>";
}#end of (move_uploaded_file).

}#end of (file_exists).

}#end of (file_size).

}#end of (limitedext).

}#end of (!is_uploaded_file).

}#end of (for loop).
# print back button.
echo "<a href=\"$_SERVER[PHP_SELF]\">back</a>";
////////////////////////////////////////////////////////////////////////////////
//else if the form didn't submitted then show it.
}else{
echo " <h3>Select files to upload!.</h3>
Max file size = ". $size_bytes / 1024 ." KB";
echo " <form method=\"post\" action=\"$_SERVER[PHP_SELF]\" enctype=\"multipart/form-data\">";
// show the file input field based on($num_files).
for ($i = 1; $i <= $num_files; $i++) {
echo "File $i: <input type=\"file\" name=\"file". $i ."\"><br>";
}
echo " <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$size_bytes\">
<input type=\"submit\" name=\"upload_form\" value=\"Upload Now!\">
</form>";
}
$data = "<table border='1'>
<tr><td>User IP Address:</td><td>$input1</td></tr>
<tr><td>Name:</td><td>$input2</td></tr>
<tr><td>Email Address:<td>$input3</td></tr>
<tr><td>Date Submitted:</td><td>$input4</td></tr>
<tr><td>Description</td><td><textarea cols='50' rows='5'>$input6</textarea></td></tr>
<tr><td>File 1 Location:</td><td>$file1</td></tr>
<tr><td>File 2 Location:</td><td>$file2</td></tr></table>";


if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}

// Write $somecontent to our opened file.
if (fwrite($handle, $data) === FALSE) {
echo "Cannot write to file";
exit;
}

echo "Success your information has been submitted! Now please submit your files...";

fclose($handle);

}
} else{
echo "You must fill out all fields properly";
}


I think its the last validation if statement... the one that says if everythings ready show the upload form...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum