FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Frst foray into PHP _SELF
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Frst foray into PHP _SELF [message #169976] Sat, 02 October 2010 17:07 Go to next message
Twayne is currently offline  Twayne
Messages: 135
Registered: September 2010
Karma: 0
Senior Member
Hi All,
Long time no see. Been ill, but back now!

Windows XP SP3+, Local XAMPP with Apache, PHP 5.2.5 .

My query is to find out if the following is OK to do, or could cause
problems. I created it accidentally and when I looked it over, it looks
strange (to me) but it worked at first and now won't work. Specifically. The
original is based on a tutorial but I forget which one now:
=============
....
if (!isset($_POST['submit'])) { // if page wasn't submitted to itself echo
the form.
?>

<html>
<head>
<title>Personal INFO</title>
</head>
<body>

<form method="post" action="<?php echo $PHP_SELF;?>">
....
lots of HTML code
....
</form>
<? php

} else { <---------- My concern is this line considering all the HTML code
between the earlier if statement and here. ----->
# Line 55 indication steady when moving any below.;
echo "Hello, ".$Fname." ".$Lname.".<br />";
....
?>
==================
In other words, I use close PHP tag, do a lot of HTML work, then jump back
into PHP and complete the If statement (specifically the ELSE portion). Is
there anything wrong with doing that?
It's my first try at PHP's _SELF for forms.
It worked a couple times and then just stopped. IE8 and FF's latest. All
testing was done locally as I've done for years now before uploading to the
servers. Oh, and yes, I've tried doing a Restart of Windows.
Why am I doing this? Seems like it would be faster and more efficient.
Yes?

Please, avoid the temptation to advise me about sanitizing and verifyiing,
etc.; I purposely wrote this test file without them to follow the KISS
methodology. Also I'm trying to avoid usiing separate PHP files for doing
the form input data checks because this seems more efficient and probably
faster to execute. Seems kinder to the user, too.

Thanks for any comments or corrections needed. I'm also open to better
methods if there are any. Hope you can understand what I meant above; looks
clear to me<g>!

Regards,

Twayne`

--
Life is the only real counselor; wisdom unfiltered
through personal experience does not become a
part of the moral tissue.
Re: Frst foray into PHP _SELF [message #169977 is a reply to message #169976] Sat, 02 October 2010 17:27 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 10/2/2010 1:07 PM, Twayne wrote:
> Hi All,
> Long time no see. Been ill, but back now!
>
> Windows XP SP3+, Local XAMPP with Apache, PHP 5.2.5 .
>
> My query is to find out if the following is OK to do, or could cause
> problems. I created it accidentally and when I looked it over, it looks
> strange (to me) but it worked at first and now won't work. Specifically. The
> original is based on a tutorial but I forget which one now:
> =============
> ...
> if (!isset($_POST['submit'])) { // if page wasn't submitted to itself echo
> the form.
> ?>
>
> <html>
> <head>
> <title>Personal INFO</title>
> </head>
> <body>
>
> <form method="post" action="<?php echo $PHP_SELF;?>">
> ...
> lots of HTML code
> ...
> </form>
> <? php
>
> } else {<---------- My concern is this line considering all the HTML code
> between the earlier if statement and here. ----->
> # Line 55 indication steady when moving any below.;
> echo "Hello, ".$Fname." ".$Lname.".<br />";
> ...
> ?>
> ==================
> In other words, I use close PHP tag, do a lot of HTML work, then jump back
> into PHP and complete the If statement (specifically the ELSE portion). Is
> there anything wrong with doing that?

Sure, nothing wrong with it at all. But what does this question have to
do with PHP_SELF?

> It's my first try at PHP's _SELF for forms.
> It worked a couple times and then just stopped. IE8 and FF's latest. All
> testing was done locally as I've done for years now before uploading to the
> servers. Oh, and yes, I've tried doing a Restart of Windows.
> Why am I doing this? Seems like it would be faster and more efficient.
> Yes?
>

Sure, it's not at all uncommon to have html within a PHP conditional.

If it's not working, enable all error processing and display your
errors. And make sure you display the page source from your browser to
catch any invalid html the browser may not be displaying.


> Please, avoid the temptation to advise me about sanitizing and verifyiing,
> etc.; I purposely wrote this test file without them to follow the KISS
> methodology. Also I'm trying to avoid usiing separate PHP files for doing
> the form input data checks because this seems more efficient and probably
> faster to execute. Seems kinder to the user, too.
>
> Thanks for any comments or corrections needed. I'm also open to better
> methods if there are any. Hope you can understand what I meant above; looks
> clear to me<g>!
>
> Regards,
>
> Twayne`
>


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Frst foray into PHP _SELF [message #169978 is a reply to message #169976] Sat, 02 October 2010 17:37 Go to previous messageGo to next message
Norman Peelman is currently offline  Norman Peelman
Messages: 126
Registered: September 2010
Karma: 0
Senior Member
Twayne wrote:
> Hi All,
> Long time no see. Been ill, but back now!
>
> Windows XP SP3+, Local XAMPP with Apache, PHP 5.2.5 .
>
> My query is to find out if the following is OK to do, or could cause
> problems. I created it accidentally and when I looked it over, it looks
> strange (to me) but it worked at first and now won't work. Specifically. The
> original is based on a tutorial but I forget which one now:
> =============
> ...
> if (!isset($_POST['submit'])) { // if page wasn't submitted to itself echo
> the form.
> ?>
>
> <html>
> <head>
> <title>Personal INFO</title>
> </head>
> <body>
>
> <form method="post" action="<?php echo $PHP_SELF;?>">
> ...
> lots of HTML code
> ...
> </form>
> <? php
>
> } else { <---------- My concern is this line considering all the HTML code
> between the earlier if statement and here. ----->
> # Line 55 indication steady when moving any below.;
> echo "Hello, ".$Fname." ".$Lname.".<br />";
> ...
> ?>
> ==================
> In other words, I use close PHP tag, do a lot of HTML work, then jump back
> into PHP and complete the If statement (specifically the ELSE portion). Is
> there anything wrong with doing that?

No, nothing wrong... a little ugly/hard on the eyes depending on how
much you do it.

> It's my first try at PHP's _SELF for forms.
> It worked a couple times and then just stopped. IE8 and FF's latest. All
> testing was done locally as I've done for years now before uploading to the
> servers. Oh, and yes, I've tried doing a Restart of Windows.
> Why am I doing this? Seems like it would be faster and more efficient.
> Yes?
>

Not a browser issue.

> Please, avoid the temptation to advise me about sanitizing and verifyiing,
> etc.; I purposely wrote this test file without them to follow the KISS
> methodology. Also I'm trying to avoid usiing separate PHP files for doing
> the form input data checks because this seems more efficient and probably
> faster to execute. Seems kinder to the user, too.
>
> Thanks for any comments or corrections needed. I'm also open to better
> methods if there are any. Hope you can understand what I meant above; looks
> clear to me<g>!
>
> Regards,
>
> Twayne`
>

Rather than close the PHP tag, whynot use the HEREDOC syntax? It's
basically a super-quote around a large chunk of text but you don't leave
the interpreter - all variable expansion works.

---code---

echo <<< DLMTR

all the $html you want with {$variable} expansion, yes even
{$arrays[0][1]["example"]}.

DLMTR;

---end---

Of course DLMTR can be your choice. With this method you can
basically build a template within the script.

--
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-
Re: Frst foray into PHP _SELF [message #169979 is a reply to message #169977] Sat, 02 October 2010 20:17 Go to previous messageGo to next message
Twayne is currently offline  Twayne
Messages: 135
Registered: September 2010
Karma: 0
Senior Member
In news:i87q3a$810$1(at)news(dot)eternal-september(dot)org,
Jerry Stuckle <jstucklex(at)attglobal(dot)net> typed:
> On 10/2/2010 1:07 PM, Twayne wrote:
>> Hi All,
>> Long time no see. Been ill, but back now!
>>
>> Windows XP SP3+, Local XAMPP with Apache, PHP 5.2.5 .

....
>>
>> <form method="post" action="<?php echo $PHP_SELF;?>">
>> ...
>> lots of HTML code
>> ...
>> </form>
>> <? php
>>
>> } else {<---------- My concern is this line considering

>> ...

>>>
>> ==================
>> In other words, I use close PHP tag, do a lot of HTML
>> work, then jump back into PHP and complete the If
>> statement (specifically the ELSE portion). Is there
>> anything wrong with doing that?
>
> Sure, nothing wrong with it at all. But what does this
> question have to do with PHP_SELF?

lol! Well, to this perpetual newbie at least, I suppose you're right if
you're thinking "not much" for an answer. But, if as I've done in the past
using separate php pages to sterilize etc.. my inputs, I guess I just didn't
notice that I'd actually done similar things many times. Changing over to
'htmlentities($_SERVER['PHP_SELF'])' switching over to it created my
confusion. I agree I could have put more thought into the Subject line.

>
>> It's my first try at PHP's _SELF for forms.

....
Why am I
>> doing this? Seems like it would be faster and more
>> efficient. Yes?
>>
>
> Sure, it's not at all uncommon to have html within a PHP
> conditional.

Thanks; that's the specific confirmation I was looking for.

>
> If it's not working, enable all error processing and
> display your errors. And make sure you display the page
> source from your browser to catch any invalid html the
> browser may not be displaying.

Ouch! I should know better. Trying to do too many things at once.

Thanks much,

Twayne`


>
>
....

Regards,

Twayne`
Re: Frst foray into PHP _SELF [message #169980 is a reply to message #169978] Sat, 02 October 2010 20:25 Go to previous message
Twayne is currently offline  Twayne
Messages: 135
Registered: September 2010
Karma: 0
Senior Member
In news:4ca76de4$0$14855$9a6e19ea(at)unlimited(dot)newshosting(dot)com,
Norman Peelman <npeelman(at)cfl(dot)rr(dot)com> typed:
> Twayne wrote:

....

>
> Rather than close the PHP tag, whynot use the HEREDOC
> syntax? It's basically a super-quote around a large chunk
> of text but you don't leave the interpreter - all variable
> expansion works.

Hmm, you know, I might just play around with that. Might be interestng and
I'm in sandbox mode anway... Got so many cat skins around now, a few more
won't hurt<g>.

>
> ---code---
>
> echo <<< DLMTR
>
> all the $html you want with {$variable} expansion, yes even
> {$arrays[0][1]["example"]}.
>
> DLMTR;
>
> ---end---
>
> Of course DLMTR can be your choice. With this method you
> can basically build a template within the script.

Thanks,

Twayne`
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Problems modifying date using regex
Next Topic: Is PHP solution for web scripts?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 22:08:25 GMT 2024

Total time taken to generate the page: 0.02680 seconds