| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| NamePros Regular | PHP Form Script Ok this may sound like a silly question but I have written up a PHP form script which when filled out: Sends the information in the form fields to the webmaster. Sends an email to the person who filled out the form telling them it has been successfully filled out. Ok well that part of it is fine. The problem is when someone visits the page it sends a blank form to the webmaster as if they already hit submit before they filled anything out. If anyone has a solution to this please post here. Here is my script: PHP Code: BTW: If that looks really silly or anything it's because I learned PHP today LOL. It's pretty simple though. Next I'm going to PHP with mySQL.
__________________ --Alpha |
| |
| | #2 (permalink) |
| NamePros Member | Do you have the form code and the php script code all in the same file or are they in two seperate files? If they are in the same file try spliting them up into two files so that the php script is not executed every time the form page is load. I think thats what your problem is. Over and out:-) |
| |
| | #3 (permalink) |
| NamePros Regular | Your problem is in line 20. This line is triggered every time the file is called upon. So when it loads its triggered. This is when this blank file is sent, every time its loaded. Try adding an if statement similar to the one you already have. Make it check for a message, name, reply email address, etc.. etc.. and then within that if statement put the mail() command that you have from line 20. The if statement you already have may infact do aswell. This should fix the problem, let me know.
__________________ Sometimes I lay awake at night and I ask "Where have I gone wrong?" Then a little voice says "This is going to take more than one night" |
| |
| | #4 (permalink) | |
| NamePros Regular | Quote:
![]() OK one last question. I made an if statement that looks like this: if ($name == "" || $email == "" || $comments == "") { echo "Please fill in all fields!"; How do I get it so that if they don't fill the fields it doesn't send the email? Thanks.
__________________ --Alpha | |
| |
| | #6 (permalink) |
| Senior Member | PHP Code: You just need to rearrange your if else blocks to something like the above to prevent it from sending email when all the fields aren't filled in. Keep the mailto in an if statement and that should work. That should also solve your problem with having the code in the same file. There's so many different ways you could go about it. Here's a couple more examples: PHP Code: Without using php to print out your form code: PHP Code: |
| |
| | #7 (permalink) |
| NamePros Regular | Ok thanks deadserious I'll try some of them and see which one works best then I'll edit the message and let you know. Thanks again!OK, how's this look? I there's something I am not noticing apparently because it still emails me blank pages lol: PHP Code:
__________________ --Alpha |
| |
| | #8 (permalink) |
| Senior Member | Try it like this: PHP Code: $name=$_GET['name']; $comments=$_GET['comments']; $to="webmaster@whatever.com"; $message="$name just filled in your comments form. They said:n$commentsnnTheir e-mail address was: $email"; They don't appear to be getting used in the script anywhere. EDIT: I see you were using them variables in the first little snippet of code you posted. ![]() |
| |
| | #9 (permalink) |
| NamePros Regular | Thanks everyone (especially deadserious) for your help. That was basically a little test script I was writing. Now that my PHP book came in I can learn how to make more sophisticated, interesting stuff. PHP is my favorite programming language now
__________________ --Alpha |
| |
| | #11 (permalink) |
| NamePros Regular | Ok the PHP book says to write this HTML form. <HTML> <HEAD> <TITLE>Project 4-1</TITLE> </HEAD> <BODY> <FORM METHOD="POST" ACTION="p-4-1.php"> <H2>Contact List</H2> <BR>Nickname: <BR><INPUT TYPE="TEXT" NAME="Nickname"> <BR> <BR>Full Name: <BR><INPUT TYPE="TEXT" NAME="Fullname"> <BR> <BR>Memo: <BR><TEXTAREA NAME="Memo" ROWS="4" COLS="40" WRAP="PHYSICAL"> </TEXTAREA> <BR> <BR> <INPUT TYPE="SUBMIT"> </FORM> </BODY> </HTML> The PHP script that the book says to write is: PHP Code: I found that to be incorrect so I changed it to: PHP Code:
__________________ --Alpha |
| |
| | #12 (permalink) |
| NamePros Member | The problem you are having is in PHP 4.2 and on, on installation, PHP by default sets register_globals to off. register_globals was the php.ini setting that allowed the above use of $variable. Until 4.2, register_globals was set to "on". However, in order to stem the flow of potentially insecure code, the PHP Group have turned register_globals off by default. Where as with previous versions of PHP you could simply do, PHP: <?php echo $variable; ?> now you need to do, PHP: <?php echo $_POST['variable']; ?> Or, if the form was using the GET method, you would use the _GET array: PHP: <?php echo $_GET['variable']; ?> If for some reason you didn't know whether you were using a POST or GET method, you could simply use the _REQUEST array like so: PHP: <?php echo $_REQUEST['variable']; ?> So your doing it right and dont worry the way your doing it will work for all versions of php. For more information, see this page in the PHP Online Manual. http://www.php.net/manual/en/languag...predefined.php |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |