RE: [PHP] Re: php form action breaks script

2012-07-02 Thread Ford, Mike
 -Original Message-
 From: Tim Dunphy [mailto:bluethu...@gmail.com]
 Sent: 28 June 2012 01:18
 
 Hey guys,
 
 It's been a little while since I've toyed with this, and I hope you
 don't mind my coming back to you for some more advice. But I've
 enjoyed some limited success with David R's advice regarding adding
 some strong quoting to the mix. Here is what I last tried -
 
  form method=post action=' . $_SERVER['[PHP_SELF'] .'

Wow! That's completely wacko! (OK, just looked at the full code and
seen it's in the middle of a single-quoted echo, so it's not that bad
after all :). You've got a spare [ in there -- the notice saying
Undefined index: [PHP_SELF should have alerted you to this, as the
index you want is just plain PHP_SELF.

   form method=post action=' . $_SERVER['PHP_SELF'] .'

 The pages do work, and the form checking code does its job (empty
 text
 displays what information is missing). Except that there is an
 annoying message that appears on screen and in the logs -
 
 Notice: Undefined index: subject in
 /Library/WebServer/Documents/examples/ch03/final/makemeelvis/sendema
 il.php
 on line 23 Notice: Undefined index: elvismail in
 /Library/WebServer/Documents/examples/ch03/final/makemeelvis/sendema
 il.php
 on line 24 Notice: Undefined index: [PHP_SELF in
 /Library/WebServer/Documents/examples/ch03/final/makemeelvis/sendema
 il.php
 on line 62

Looking at the relevant bit of your script (assume this is line 23
onward):

   $subject = $_POST['subject'];
   $text = $_POST['elvismail'];
   $output_form = false;
 
 
   if (isset($_POST['Submit'])) {

You're accessing $_POST['subject'] and $_POST['elvismail'] *before* the
check to see if this is a from a form submission - on the initial access,
to just display the form, these $_POST indexes will not be set so
causing the notices.

You either need to put the assignments inside the

  if (isset($POST['Submit']))

branch, or conditionalise them in some way, such as:

$subject = isset($_POST['subject']) ? $_POST['subject'] : NULL;
$text = isset($_POST['elvismail']) ? $_POST['elvismail'] : NULL;


Another oddity in your script is that you're using the string values
true and false instead of the Boolean true and false. Because of
the way PHP typecasts, both true and false are actually regarded
as Boolean true, which could get a little confusing -- so it's much
better (and probably more efficient) to use the proper Boolean values.
Also, it enables your later test to be written, with confidence, as
just

if ($output_form) {


Also, also, with a little bit of rearrangement of the tests, you can
reduce the amount of code a bit:

if (!empty($subject)  !empty($text)) {
// Both inputs supplied -- good to go.
$output_form = false;
} else {
// At least one input missing -- need to redisplay form
$output_form = true;

if (empty($subject)) {
if (empty($text)) {
echo 'You forgot the email subject and body.br /';
} else {
echo 'You forgot the email subject.br /';
}
} else {
echo 'You forgot the email body text.br /';
}
}

Actually, I think my inclination would be to assign $output_form
first, and then do the rest of the tests:

$output_form = empty($subject) || empty($text);

if ($output_form) {
// At least one input missing -- work out which one
if (empty($subject))
if (empty($text)) {
echo 'You forgot the email subject and body.br /';
} else {
echo 'You forgot the email subject.br /';
}
} else {
echo 'You forgot the email body text.br /';
}
}

That said, there are lots of personal preferences involved here, and
I'm sure others would offer different possibilities. (Me personally,
I also prefer the alternative block syntax with initial : and end...
tags -- but then, the forests of curly braces others seem to find
acceptable make my eyes go fuzzy, so go figure)

Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: m.f...@leedsmet.ac.uk T: +44 113 812 4730






To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: php form action breaks script

2012-06-27 Thread Matijn Woudt
On Thu, Jun 28, 2012 at 2:17 AM, Tim Dunphy bluethu...@gmail.com wrote:
 Hey guys,

 It's been a little while since I've toyed with this, and I hope you
 don't mind my coming back to you for some more advice. But I've
 enjoyed some limited success with David R's advice regarding adding
 some strong quoting to the mix. Here is what I last tried -

Please bottom post on this (and probably any) mailing list.


  form method=post action=' . $_SERVER['[PHP_SELF'] .'

This must be some typo, it should read
form method=post action=' . $_SERVER['PHP_SELF'] .'




  $from = 'bluethu...@jokefire.com';
  $subject = $_POST['subject'];
  $text = $_POST['elvismail'];
  $output_form = false;


Try using
$subject = isset($_POST['subject']) ? $_POST['subject'] : ;
$subject = isset($_POST['elvismail']) ? $_POST['elvismail'] : ;

Cheers,

Matijn

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: php form action breaks script

2012-06-27 Thread tamouse mailing lists
On Wed, Jun 27, 2012 at 7:17 PM, Tim Dunphy bluethu...@gmail.com wrote:
 Hey guys,

 It's been a little while since I've toyed with this, and I hope you
 don't mind my coming back to you for some more advice. But I've
 enjoyed some limited success with David R's advice regarding adding
 some strong quoting to the mix. Here is what I last tried -

  form method=post action=' . $_SERVER['[PHP_SELF'] .'

Just a wee typo here: You've quoted '[PHP_SELF' -- the extra bracket
at the beginning what's wrong there. Should just be 'PHP_SELF'.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: php form action breaks script

2012-06-27 Thread tamouse mailing lists
On Wed, Jun 27, 2012 at 7:17 PM, Tim Dunphy bluethu...@gmail.com wrote:


One more little thing:

These notices:

 Notice: Undefined index: subject in
 /Library/WebServer/Documents/examples/ch03/final/makemeelvis/sendemail.php
 on line 23 Notice: Undefined index: elvismail in
 /Library/WebServer/Documents/examples/ch03/final/makemeelvis/sendemail.php

show up because you are processing form fields in $_POST when there
might not be any yet.

These lines:

  $from = 'bluethu...@jokefire.com';
  $subject = $_POST['subject'];
  $text = $_POST['elvismail'];
  $output_form = false;


Should appear *after* this line:

  if (isset($_POST['Submit'])) {


You should also check the $_POST entries for 'subject' and 'elvismail'
to make sure they are set to avoid the notices, even if you do move
them after the submit check. You never know!

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: php form action breaks script

2012-06-27 Thread Jim Giner


Tim Dunphy bluethu...@gmail.com wrote in message 
news:caozy0em5duhby-qv+y1u-e+c5yd7g5utauhomoyu3z7jma-...@mail.gmail.com...

Notice: Undefined index: subject in
/Library/WebServer/Documents/examples/ch03/final/makemeelvis/sendemail.php
on line 23 Notice: Undefined index: elvismail in
/Library/WebServer/Documents/examples/ch03/final/makemeelvis/sendemail.php
on line 24 Notice: Undefined index: [PHP_SELF in
/Library/WebServer/Documents/examples/ch03/final/makemeelvis/sendemail.php
on line 62

[Wed Jun 27 20:13:42 2012] [error] [client 127.0.0.1] PHP Notice:
Undefined index: [PHP_SELF in
/Library/WebServer/Documents/examples/ch03/final/makemeelvis/sendemail.php
on line 62, referer: http://localhost/elvis/


You're missing an input (POST) for the field named 'subject'.  Something 
change in your html?  As in you no longer have a 'subject' input field? 
Same for the other field named.  As for the missing PHP_SELF - did you start 
a session?  I could be way off on this.  The errors are even giving you the 
line number so it shouldn't be hard to find!




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: php form action breaks script

2012-06-15 Thread ma...@behnke.biz


Al n...@ridersite.org hat am 15. Juni 2012 um 14:29 geschrieben:



 On 6/14/2012 7:28 PM, Tim Dunphy wrote:
  However if I change the form action to this, it breaks the page
  resulting in a white screen of death:


error_reporting(E_ALL);
ini_set('display_errors', 'On');

And what is the error message?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: php form action breaks script

2012-06-15 Thread Jim Lucas

On 06/15/2012 06:35 AM, Jim Giner wrote:

Hear, Hear for heredocs.  The only way to code up your html.  Took me a few
months to discover it and haven't looked back since.





The only problem I have with HEREDOC is I cannot use constants within them.

--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: php form action breaks script

2012-06-15 Thread ma...@behnke.biz


Jim Lucas li...@cmsws.com hat am 15. Juni 2012 um 18:39 geschrieben:

 On 06/15/2012 06:35 AM, Jim Giner wrote:
  Hear, Hear for heredocs.  The only way to code up your html.  Took me a few
  months to discover it and haven't looked back since.
 
 
 

 The only problem I have with HEREDOC is I cannot use constants within them.

You shouldn't use constants anyway. Always inject your dependencies.



 --
 Jim Lucas

 http://www.cmsws.com/
 http://www.cmsws.com/examples/

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

Marco Behnke
Dipl. Informatiker (FH), SAE Audio Engineer Diploma
Zend Certified Engineer PHP 5.3

Tel.: 0174 / 9722336
e-Mail: ma...@behnke.biz

Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal

http://www.behnke.biz

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: php form action breaks script

2012-06-15 Thread Al
It is a small price to pay for large block, especially if the text has any 
quotes. Personally, I can't keep them straight and delimit them, etc.  Heredoc 
saves all that such stuff.


$insert= MY_DEFINED;

echo hdc
This is my $insert
hdc;


On 6/15/2012 12:39 PM, Jim Lucas wrote:

On 06/15/2012 06:35 AM, Jim Giner wrote:

Hear, Hear for heredocs. The only way to code up your html. Took me a few
months to discover it and haven't looked back since.





The only problem I have with HEREDOC is I cannot use constants within them.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: php form action breaks script

2012-06-14 Thread Paul Halliday
On Thu, Jun 14, 2012 at 10:17 PM, David Robley robl...@aapt.net.au wrote:
 Tim Dunphy wrote:

 Hello list,

  I was just wondering if I could get some opinions on a snippet of
 code which breaks a php web page.

  First the working code which is basically an html form being echoed by
  php:

 if ($output_form) {

   echo 'br /br /form action=sendemail.php method=post  

form action=sendemail.php

should be:

form action=sendemail.php ...

   label for=subjectSubject of email:/labelbr /
   input id=subject name=subject type=text size=30 /br /
   label for=elvismailBody of email:/labelbr /
    textarea id=elvismail name=elvismail rows=8
 cols=40/textareabr /
    input type=submit name=Submit value=Submit /
   /form';


   }

 However if I change the form action to this, it breaks the page
 resulting in a white screen of death:


   if ($output_form) {

   echo 'br /br /form action=?php echo $_SERVER['PHP_SELF']; ?
 method=post  
   label for=subjectSubject of email:/labelbr /
   input id=subject name=subject type=text size=30 /br /
   label for=elvismailBody of email:/labelbr /
    textarea id=elvismail name=elvismail rows=8
 cols=40/textareabr /
    input type=submit name=Submit value=Submit /
   /form';


   }

 Reverting the one line to this:

 echo 'br /br /form action=sendemail.php method=post  

 gets it working again. Now I don't know if it's an unbalanced quote
 mark or what's going on. But I'd appreciate any advice you may have.


 Best,
 tim

 If you check your apache log you'll probably see an error message. But the
 problem seems to be that your string you are trying to echo is enclosed in
 single quotes, and contains a string in ?php tags. Try something like

 echo 'br /br /form action=' . $_SERVER['PHP_SELF'] . '
 method=post ...etc



 Cheers
 --
 David Robley

 I haven't had any tooth decay yet, said Tom precariously.
 Today is Sweetmorn, the 20th day of Confusion in the YOLD 3178.


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
Paul Halliday
http://www.squertproject.org/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php