php-general Digest 2 Oct 2009 12:38:04 -0000 Issue 6369

Topics (messages 298455 through 298476):

Re: Self-Process php forms or not?
        298455 by: MEM
        298458 by: Manuel Lemos
        298463 by: kranthi
        298466 by: Manuel Lemos
        298467 by: Manuel Lemos
        298469 by: kranthi
        298470 by: kranthi
        298472 by: Ashley Sheridan
        298473 by: kranthi

Re: Parse Question Using list()
        298456 by: cool.hosting4days.com
        298459 by: Jim Lucas

Re: Curl output
        298457 by: Paul M Foster
        298460 by: Jim Lucas
        298462 by: kranthi
        298471 by: Ashley Sheridan
        298474 by: kranthi
        298475 by: Ashley Sheridan
        298476 by: kranthi

iconv - bad encoding
        298461 by: Jarosek

Re: Incorrect _SERVER['SERVER_PORT'] returned??
        298464 by: kranthi

Re: PHP/MySQL Superstars
        298465 by: Jerome Botbol

Re: WYSIWYG editor to change textarea
        298468 by: kranthi

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
Thanks a lot to all,

I will see what best fits my limited knowledge, and choose the possible
option.

Regards,
Márcio

> -----Original Message-----
> From: Tom Worster [mailto:[email protected]]
> Sent: quinta-feira, 1 de Outubro de 2009 20:11
> To: tedd; 'PHP-General List'
> Subject: Re: [PHP] Self-Process php forms or not?
> 
> On 10/1/09 10:13 AM, "tedd" <[email protected]> wrote:
> 
> > At 1:00 PM +0100 10/1/09, MEM wrote:
> >> One last question about this:
> >>
> >> I've done a self submit form, after hearing all the advantages
> expressed
> >> here.
> >> But how could we relate, without using javascript, a self submit
> form with a
> >> "success page" or a "confirmation page" that doesn't show the form?
> >>
> >> Can please someone throw me some infos about this please?
> >
> >
> > MEM:
> >
> > Here's what I do -- it's pretty simple.
> >
> > I use a hidden input variable I call "step" and monitor it as the
> > user clicks whatever form submit they are on -- it works like so:
> >
> > $step = isset($_POST['step']) ? $_POST['step'] : 0;
> >
> > switch ($step)
> >     {
> >    case 0: // present the first form to the user
> >    // collect data
> >    // you can enhance the user experience by using javascript here.
> >    // <input type=hidden name=step value=1>
> >     break;
> >
> >    case 1: // present second form to the user
> >    // clean data
> >    // if data OK then record data in db <input type=hidden name=step
> value=2>
> >    // if data not OK then send user back <input type=hidden name=step
> value=0>
> >     break;
> >
> >    case 2: //present the third form to the user
> >    // success, or confirmation, or thank you page
> >     break;
> >     }
> >
> > Now, to make things easier for the user, be sure to set session
> > variables for all the data collected in the first form so that IF you
> > send the user back to the first form, the user doesn't have to
> > reenter everything.
> 
> i do pretty much the same thing. each form in my html template files
> has a
> form name tucked away in a hidden input element. the only difference
> from
> your method is that the names are unique across the application.
> 
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php


--- End Message ---
--- Begin Message ---
Hello,

on 10/01/2009 09:00 AM MEM said the following:
> One last question about this:
> 
> I've done a self submit form, after hearing all the advantages expressed
> here. 
> But how could we relate, without using javascript, a self submit form with a
> "success page" or a "confirmation page" that doesn't show the form?
> 
> Can please someone throw me some infos about this please?
> 
> 
> Ps- I've googled: "php redirect success page on self submit form" and
> similar... 

All you need to do is to include an hidden field in the form. Then check
the respective $_POST or $_GET variable is set. If it is not set, show
the form for the first time. If it is set, validate the form and process
it. If the form is not valid, show the form again with previously
submitted values.

This tutorial video explains this workflow:

http://www.phpclasses.org/browse/video/1/package/1/section/usage.html

This example script demonstrates how to setup your code. It uses a
function of a forms class name WasSubmiteed() to check if the form is
being presented for the first time or is being submitted:

http://www.meta-language.net/forms-examples.html?example=test_form&code=1

-- 

Regards,
Manuel Lemos

Find and post PHP jobs
http://www.phpclasses.org/jobs/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

--- End Message ---
--- Begin Message ---
I try to avoid the use of hidden form elements as much as possible,
especially for tracking whether a user has submitted a form or not...

I use name="submit" for the submit button instead, that will pass the
value of the submit button to the action script.

above all i use a template engine, smarty to take care of the
presentation for me(like deciding whether to show the form and/or a
success/failure message)

--- End Message ---
--- Begin Message ---
Hello,

on 10/02/2009 04:41 AM kranthi said the following:
> I try to avoid the use of hidden form elements as much as possible,
> especially for tracking whether a user has submitted a form or not...
> 
> I use name="submit" for the submit button instead, that will pass the
> value of the submit button to the action script.
> 
> above all i use a template engine, smarty to take care of the
> presentation for me(like deciding whether to show the form and/or a
> success/failure message)

That only works if the user clicks on that submit button. If the user
hits the enter key in a text input, the form is submitted but the submit
input variable is not set. That is why an hidden input is a safer solution.

-- 

Regards,
Manuel Lemos

Find and post PHP jobs
http://www.phpclasses.org/jobs/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

--- End Message ---
--- Begin Message ---
Hello,

on 10/02/2009 04:41 AM kranthi said the following:
> I try to avoid the use of hidden form elements as much as possible,
> especially for tracking whether a user has submitted a form or not...
> 
> I use name="submit" for the submit button instead, that will pass the
> value of the submit button to the action script.
> 
> above all i use a template engine, smarty to take care of the
> presentation for me(like deciding whether to show the form and/or a
> success/failure message)

That only works if the user clicks on that submit button. If the user
hits the enter key in a text input, the form is submitted but the submit
input variable is not set. That is why an hidden input is a safer solution.

-- 

Regards,
Manuel Lemos

Find and post PHP jobs
http://www.phpclasses.org/jobs/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

--- End Message ---
--- Begin Message ---
>> That only works if the user clicks on that submit button. If the user
>> hits the enter key in a text input, the form is submitted but the submit
>> input variable is not set. That is why an hidden input is a safer solution.

i doubt that, because i use the above mentioned method in nearly all
of my projects, and all of them are working fine.

P.S: i prefer keyboard to mouse as a input device

--- End Message ---
--- Begin Message ---
and yes i forgot to mention... i avoid hidden form elements because
they can be modified very easily and hence pose a security threat.

--- End Message ---
--- Begin Message ---
On Fri, 2009-10-02 at 13:55 +0530, kranthi wrote:
> and yes i forgot to mention... i avoid hidden form elements because
> they can be modified very easily and hence pose a security threat.
> 

You say you don't use hidden fields because they can be modified too
easily, yet you say you check for the submit button? Which out of the
two do you do, as last time I checked, modifying one form field is as
easy as changing any other!

Also worth noting, you can only successfully check for the name="submit"
value if there is only one submit button in your form, as that is then
the default (and only) submit that the form can use, so it uses that. If
you have more than one submit button (and this includes image input
elements) then using the keyboard will use the first submit field it
finds I believe.

Thanks,
Ash
http://www.ashleysheridan.co.uk




--- End Message ---
--- Begin Message ---
>> You say you don't use hidden fields because they can be modified too
>> easily, yet you say you check for the submit button? Which out of the
>> two do you do, as last time I checked, modifying one form field is as
>> easy as changing any other!
I completely agree with you. changing submit text is as easy as
changing hidden fields, but its less likely for a user to modify a
submit button as compared to a hidden field. moreover it just reduces
my typing load. (This is just my practice)

>> Also worth noting, you can only successfully check for the name="submit"
>> value if there is only one submit button in your form, as that is then
>> the default (and only) submit that the form can use, so it uses that. If
>> you have more than one submit button (and this includes image input
>> elements) then using the keyboard will use the first submit field it
>> finds I believe.
Cant agree with you on this though. as far as i know using name=""
(names of the two buttons may/may not be unique) is the only way to
track form submission for forms with multiple submit buttons. Please
point out if you think otherwise

-- 
Kranthi.

--- End Message ---
--- Begin Message ---

On Oct 1, 2009, at 5:02 PM, Ben Dunlap wrote:

You could tackle this in a couple of different ways. Either split your
string into an array first:

$line = fgets($handle);
$columns = explode(",", trim($line));

Thanks Ben - the explode() command worked great!

---------

Now a bit of another problem

I'm exporting from another database (mac) to a csv file then a quick import to excel 2004 (mac) for some cleaning...

before the excel import, some date fields look like "2009-9-29 11:21:37" = good for sql import

but excel does an auto reformat to

9/29/2009  11:21:37 AM = not good for sql import


Q: any way to turn this auto reformat off in excel and keep it the way I had it? (I saw nothing in pref's)


Thanks,
[email protected]






--- End Message ---
--- Begin Message ---
[email protected] wrote:

On Oct 1, 2009, at 5:02 PM, Ben Dunlap wrote:

You could tackle this in a couple of different ways. Either split your
string into an array first:

$line = fgets($handle);
$columns = explode(",", trim($line));

Thanks Ben - the explode() command worked great!


Use the tool that PHP provides for such problems.

http://php.net/fgetcsv

---------

Now a bit of another problem

I'm exporting from another database (mac) to a csv file then a quick import to excel 2004 (mac) for some cleaning...

before the excel import, some date fields look like "2009-9-29 11:21:37" = good for sql import

but excel does an auto reformat to

9/29/2009  11:21:37 AM = not good for sql import


Q: any way to turn this auto reformat off in excel and keep it the way I had it? (I saw nothing in pref's)


try using strtotime() on that field and see if it works.

http://php.net/strtotime

I'm pretty sure that function will handle it.


Thanks,
[email protected]








--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare

--- End Message ---
--- Begin Message ---
On Thu, Oct 01, 2009 at 04:37:14PM -0700, gbhumphrey wrote:

> 
> Hi, I am doing a basical curl call and can get the webpage I want. However
> when it prints to the screen, it only prints the text, not css or any
> javascript calls that run on page load.
> Is there a way to make it do that?
> 
> thanks
> using a basic curl call
> $curl_handle=curl_init();
> curl_setopt($curl_handle,CURLOPT_URL,'http://example.com');
> curl_setopt($ch, CURLOPT_RETURNTRANSFER,0); // return into a variable
> curl_exec($curl_handle);

I don't know about the javascript, but if the CSS is an external file,
then it wouldn't get dragged along with the original file, and thus
wouldn't be there to style anything on the HTML page. Just a guess.

Paul

-- 
Paul M. Foster

--- End Message ---
--- Begin Message ---
gbhumphrey wrote:
Hi, I am doing a basical curl call and can get the webpage I want. However
when it prints to the screen, it only prints the text, not css or any
javascript calls that run on page load.
Is there a way to make it do that?

thanks
using a basic curl call
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'http://example.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,0); // return into a variable
curl_exec($curl_handle);






Along the lines of what Paul has already alluded to, you will probably find upon further examination of the html source that the "linked" files (js, css, etc...) are probably using relative paths, not absolute paths including the domain name.

To fix this, you would have to do a little source code rewriting to add the full domain name and directory path information to the "linked" in url structure.

I know if you do this with wget (cli app) that you can have it re-write the domain + path url references. But, I'm not sure if cURL has an option for that. You might RTM on the cURL options page to find out.

http://php.net/curl


--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare

--- End Message ---
--- Begin Message ---
using the <base tag is a solution to your problem if the links are relative..
http://www.w3schools.com/TAGS/tag_base.asp
but I am not sure if base tag works outside <html></html>....

try... <base href="URL"></base> before curl_init()
where URL is parsed using PHP's parse_url() function on http://example.com

in either case if there are any external js/css files cURL wont fetch
external files(and if they are internal/inline your browser should
display them already).. your browser will have to fetch them for you,
net console of firebug will be helpful in that case.

--- End Message ---
--- Begin Message ---
On Fri, 2009-10-02 at 12:51 +0530, kranthi wrote:
> using the <base tag is a solution to your problem if the links are relative..
> http://www.w3schools.com/TAGS/tag_base.asp
> but I am not sure if base tag works outside <html></html>....
> 
> try... <base href="URL"></base> before curl_init()
> where URL is parsed using PHP's parse_url() function on http://example.com
> 
> in either case if there are any external js/css files cURL wont fetch
> external files(and if they are internal/inline your browser should
> display them already).. your browser will have to fetch them for you,
> net console of firebug will be helpful in that case.
> 

Some browser security settings may not allow you to run Javascript code
that exists on another server though. The <base> tag can be used to
reference the external CSS and Javascript, but watch out for security
settings on client agents.

Thanks,
Ash
http://www.ashleysheridan.co.uk




--- End Message ---
--- Begin Message ---
>> Some browser security settings may not allow you to run Javascript code
>> that exists on another server though
not many users use those kind of browsers, because if they do most of
the websites which use CDNs will not work.

Firstly, it is not a good idea to fetch an entire web page and snow it
to an user. (use iframes if this is a must)
Secondly, this idea may not be feasible if the web page in question
uses AJAX, because none of the browsers allow cross domain AJAX
requests

As a side note, use str_replace("<head>", "<head><base....></base>",
$text) if base tag doesnot work

On 02/10/2009, Ashley Sheridan <[email protected]> wrote:
> On Fri, 2009-10-02 at 12:51 +0530, kranthi wrote:
>> using the <base tag is a solution to your problem if the links are
>> relative..
>> http://www.w3schools.com/TAGS/tag_base.asp
>> but I am not sure if base tag works outside <html></html>....
>>
>> try... <base href="URL"></base> before curl_init()
>> where URL is parsed using PHP's parse_url() function on http://example.com
>>
>> in either case if there are any external js/css files cURL wont fetch
>> external files(and if they are internal/inline your browser should
>> display them already).. your browser will have to fetch them for you,
>> net console of firebug will be helpful in that case.
>>
>
> Some browser security settings may not allow you to run Javascript code
> that exists on another server though. The <base> tag can be used to
> reference the external CSS and Javascript, but watch out for security
> settings on client agents.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
>


-- 
Kranthi.

--- End Message ---
--- Begin Message ---
On Fri, 2009-10-02 at 15:59 +0530, kranthi wrote:
> not many users use those kind of browsers, because if they do most of
> the websites which use CDNs will not work.

I've read that the upcoming Firefox 4 may have some features built in
for this sort of thing, and there are plugins out there for most
browsers that can do this as an added layer of security.

On this front though, has anyone else read about Microsofts Gazelle
browser/os? I'm not trying to plug it here or anything (I'm an anti
Windows person myself!) but the concept looks interesting. It goes
further than Chrome where each tab has it's own process by giving each
domain specific object its own process/sandbox.

Thanks,
Ash
http://www.ashleysheridan.co.uk




--- End Message ---
--- Begin Message ---
>> I've read that the upcoming Firefox 4 may have some features built in
>> for this sort of thing, and there are plugins out there for most
>> browsers that can do this as an added layer of security.
Sorry but I could not understand what you meant by "this"

coming back to original problem... you should keep in mind that if
base tag is used, the links (<a href="...">) in that page will become
absolute links instead of relative links

--- End Message ---
--- Begin Message ---
Hello

I noticed a problem using iconv, but investigation showed, that this is
not exectly the iconv itself, but something like php encoding.

From the beginning:

a hava an incoming variable $text;
it has some Polish diactics 'strona główna'.
I expect to remove diactics : 'strona glowna'.

So I use iconv: iconv('utf-8', 'us-ascii//TRANSLIT', $text)

and unfortunetly i get: 'strona g??wna' ... But only under apache, in
browser

The same file, command, etc run from bash gives: 'strona glowna' ... OK
So i think : "bad config", but double checked and configs are
identical... (cli and apache2)

Best part: for 2 or 3 times after starting computer (debian), it didn't
worker until I did: (apache start && apache stop - not apache restart),
then it worked. Now it doesn't work any more. No other config (except
php was changed).

Any ideas?





--- End Message ---
--- Begin Message ---
i dont have any idea about your problem, but just an idea....

have you used https://localhost in the browser while trying to check
_SERVER['SERVER_PORT'] ?

--- End Message ---
--- Begin Message ---
Thanks Manuel your input is greatly appreciated.

Jerome 

-----Original Message-----
From: Manuel Lemos [mailto:[email protected]] 
Sent: 01 October 2009 20:46
To: Jerome Botbol
Cc: [email protected]
Subject: Re: PHP/MySQL Superstars

Hello,

on 10/01/2009 10:09 AM Jerome Botbol said the following:
> Hi All,
> 
> We require a PHP / MySQL superstar to work in-house at our offices near
> Edgware, London for 3 months on a ground breaking new web 2.0 project
> which involves a variety of exciting new technologies. You will need at
> least 2 years proven experience on commercial projects. Relevant
> experience on the CI framework is a must.
> 
> You will be working with an actionscript and front-end XHTML developer,
> a framework developer who is providing a database design and class
> system and a design team.
> 
> Please email your CV to [email protected] (reference PG-tech-01)  or
> feel free to contact me directly. 
> 
> Please let me know if this is of interest to you.

You may want to submit your job post in the PHPClasses job board. There
are many thousands of PHP developers registered to get notifications
about jobs that match their skills.

http://www.phpclasses.org/jobs/

If you prefer to tune your search by country and skill, you may want to
browse the PHP professionals directory and check the skills in the
search form as you wish:

http://www.phpclasses.org/professionals/


-- 

Regards,
Manuel Lemos

Find and post PHP jobs
http://www.phpclasses.org/jobs/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/


--- End Message ---
--- Begin Message ---
I would recommend using an open framework like yui/dojo/jquery for ALL
your javascript needs..(i personally prefer jquery) each of the above
mentioned frameworks have wysiwyg editors of their own.

try using http://code.google.com/p/jwysiwyg/ i doubt it will conflict
with your javascript with compatibility mode ON
http://docs.jquery.com/Using_jQuery_with_Other_Libraries

TinyMCE as such is a very good plugin (i use that in nearly all of my
projects and never faced a problem with it). may be you should try to
debug your code that is conflicting with tinyMCE

--- End Message ---

Reply via email to