logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 02-03-2010, 09:07 PM   #1
javierrebelde
 
Join Date: Jan 2009
Posts: 46
Default prevent post action file send empty email

Hi,

I got this problem i create a form file "reservation.php" and a action file "sendreservation.php" ok this is what i need.

It is anyway i can prevent "sendreservation.php" send a empty email if someone access that file directly example:

http://www.mydomain.com/sendreservation.php
javierrebelde is offline   Reply With Quote
Old 02-03-2010, 11:49 PM   #2
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,214
Default

if ($_SERVER["REQUEST_METHOD"] <> "POST")
die("<h1>You can only reach this page by posting from the html form<h1>");
maybe
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 02-04-2010, 06:50 AM   #3
javierrebelde
 
Join Date: Jan 2009
Posts: 46
Default

Hmm. I need more info because i dont undertand what i have to do with that. Btw the posting page is php not html
javierrebelde is offline   Reply With Quote
Old 02-04-2010, 07:50 AM   #4
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,214
Default

just put it at the begining your php block
it may not be enough it just will show the message if the file is access directly
change the message to what you want
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 02-04-2010, 07:36 PM   #5
tux
tux's Avatar
 
Join Date: Feb 2007
Location: Isle of Wight, that little island right at the bottom of the UK
Posts: 657
Default

Try this, its a page with a simple form to collect name and email and a page to display the results. When the submit button is clicked it will display the results in sendmail.php. Not added any send mail function its just to validate the form so that all fields are filled in but will also redirect back to the form if you try to view sendmail.php directly.

form.php....

PHP Code:
<?php

$error    
=    $_GET['error'];

if(
$error){
$error    =    "You must fill in all fields!";
}else 
$error    =    "";

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php echo $error?>
<form name="form1" method="post" action="sendmail.php">

  <input type="hidden" name="submitted" id="submitted" value="1">
  <p>
    Name 
      <input type="text" name="name" id="name" value="">
  </p>
  <p>
    Email 
    <input type="text" name="email" id="email" value="">
</p>
  <p>
    <input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>
Notice the hidden field!


sendmail.php....

PHP Code:
<?php

$submitted    
=    $_POST['submitted'];
$name        =    $_POST['name'];
$email        =    $_POST['email'];

if(
$submitted && $name && $email){

echo 
$name."<br>";
echo 
$email;

}elseif(!
$submitted || $submitted){
header("location:form.php?error=1");
exit;
}

?>
Not sure if its what you are after but hope it helps.

Regards Paul
tux is offline   Reply With Quote
Old 02-09-2010, 05:49 AM   #6
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

I would use tux's suggestion however there is no need to implement a hidden field

PHP Code:
$submit=    $_POST['Submit']; 
$name        =    $_POST['name']; 
$email        =    $_POST['email']; 

if(
$submit && $name && $email){ 
By using $_POST[Submit] you are catching the submit button value which is also passed when submitted
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 02-09-2010, 06:03 AM   #7
tux
tux's Avatar
 
Join Date: Feb 2007
Location: Isle of Wight, that little island right at the bottom of the UK
Posts: 657
Default

Thats interesting Dj, I have always used a hidden field since it was used in your vids when you started teaching me.

Trims off a line of code, so even shorter scripts. Cheers mate.

Paul
tux is offline   Reply With Quote
Old 02-09-2010, 04:49 PM   #8
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

Those vids are sooooo old

id do them a bit different next time
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 02-09-2010, 07:45 PM   #9
tux
tux's Avatar
 
Join Date: Feb 2007
Location: Isle of Wight, that little island right at the bottom of the UK
Posts: 657
Default

They might be old but they are still a great way to learn PHP for people starting out....

.... apart from http://codezenith.co.uk/ of course.

If it wasn't for those OLD tuts I don't think I would have plunged into the sea of PHP.
tux is offline   Reply With Quote
Old 02-09-2010, 09:07 PM   #10
domedia
Administrator
domedia's Avatar
 
Join Date: Dec 2003
Posts: 9,730
Default

An old version of this was my first exposure to it:
http://articles.sitepoint.com/articl...1-installation
domedia is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:00 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com