Page 1 of 1

Form doesnt post if somthing is not submitted.

Posted: Tue Jan 24, 2006 7:49 pm
by nickman013
I have a working form with javascript validation (checks to see if somthing is entered in fields before it is submitted).
But if people go to the processor page it will submit the form with nothing on it. Like it will just submit a blank form. Any way to prevent the form from entering if a value equals nothing.

I think it would be possible to do with this.

Code: Select all

if($name==''){
 die("you did not submit anything")
}
else { ... form processor script }
I dont know if that is exactly how it would be written, but that is my idea of how to do it. Thank You!

Posted: Tue Jan 24, 2006 8:01 pm
by John Cartwright
huh? :roll:

Posted: Tue Jan 24, 2006 8:38 pm
by nickman013
haha, i dont know

i just dont want people going to the form processor page because it floods my email, i want to make a block on it, so there has to be somthing being sent for it to send? get what i mean?

Posted: Tue Jan 24, 2006 8:45 pm
by John Cartwright

Code: Select all

if(empty($_POST['name'])){
   die("you did not submit anything")
}
else { 
   ... form processor script 
}
??

Posted: Tue Jan 24, 2006 9:04 pm
by nickman013
let me explain this a bit better

i have a form

Code: Select all

<form action=process.php action=post>
<input type=text name=name>
<input type=text name=comments>
<input type=text name=vote>
process.php

Code: Select all

<?
header('Location:/pages/report.php');
include("/home/muot/dbc.php");
mysql_query("update votes set number_of_votes = number_of_votes + 1 where answer = '$vote'");
$page = "thank you - voting.";
include('/home/muot/add2stat.php');
$content = "
<tr><td><b>$name</b> voted this muot as a $vote !<br>
<b>$name said $comments</td></tr>
";
$filename = '/home/muot/public_html/pages/report.php'; 
if (is_writable($filename)) { 
if (!$handle = fopen($filename, 'a')) { 
echo "Cannot open file ($filename)"; 
exit; 
} 
if (fwrite($handle, $content) === FALSE) { 
echo "Cannot write to file ($somecontent)"; 
exit; 
} 
echo ""; 
fclose($handle); 
} else { 
echo "The file $filename is not writable"; 
} 
?>
That works, just how I want it.

But if someone goes to http://www.mysite.com/process.php , it will write blank data to a page. I want to stop the script from doing anything if there is not any data inputed.

I tried to add your script but I got a parse error, unexpected } on line 4 , line 4 is }.

Thank You!

Posted: Tue Jan 24, 2006 9:09 pm
by neophyte
Sounds like you have a syntax error. Check your { and your } and make sure they're all closed.

What you want to do is check to find out if you have a submission to the page. If there is process the page. If there isn't, don't process it. That's the concept.

Posted: Tue Jan 24, 2006 9:10 pm
by nickman013
I have the form on a different page, and the processor on another.

I just dont want people being able to go to the processor page because it will just write data, and flood the page with no results.

Thank you

Posted: Tue Jan 24, 2006 9:14 pm
by nickman013
To add to my last post, I got it working. :D I added what Jcart told me to do, and it worked. The parse error was coming from the die("blah") , Jcart forgot to add a ; at the end. Its all good.

Thanks For the Help Guys!

Posted: Tue Jan 24, 2006 9:17 pm
by John Cartwright
nickman013 wrote:To add to my last post, I got it working. :D I added what Jcart told me to do, and it worked. The parse error was coming from the die("blah") , Jcart forgot to add a ; at the end. Its all good.

Thanks For the Help Guys!
fyi I just copy and pasted your snipplet (and edited slightly).. :lol:

Posted: Tue Jan 24, 2006 9:18 pm
by nickman013
oh, lol sorry, i just thought you wrote it because the begining was a little different.

my mistake, sorry.

Posted: Tue Jan 24, 2006 9:19 pm
by John Cartwright
Nah don't be sorry, enjoy.