NYCPHP Meetup

NYPHP.org

[nycphp-talk] Can't get no $action

Dan Cech dcech at phpwerx.net
Mon Apr 26 09:28:20 EDT 2004


leam wrote:
> Sorry for the lousy joke, this one's been beating me up for days.
> 
> I'm using the editor.php script from "Beginning PHP4" (Wrox press) and 
> it uses a call to $PHP_SELF to refresh the page on submit. ($PHP_SELF is 
> set from $_SERVER[PHP_SELF]) At the end there is a switch statement that 
> is supposed to save the file if the action "save_file" is set, otherwise 
> just do the regular edit page.
> 
> I could not get their script to work so I'm breaking it down to smaller, 
> more digestible parts. What I'm currently stuck on is getting the call 
> to save the form if the submit button is clicked.
> 
>  From the editor_form function:
> 
>     echo "<form name=edit_form method=post action=$PHP_SELF >";
>     echo "<input type=hidden name=action value=save_file >";
>     echo "<input type=submit value='Save and Exit' name=submit>";

It won't be causing the problem, but your html should be properly quoted.

>  From the switch statement:
> 
>     switch($action) {
>         case "save_file":
>             save_file();   
>             break;
>         default:
>             html_header();   
>             editor_form();
>             html_footer();
>     }
> 
> The save_file function works if it's called by itself, and the $action 
> just seems to call the default.

I would suggest that your server might have register_globals turned off, 
meaning you will need to use $_POST['action'] instead of $action.  You 
should do this anyway, rather than relying on register_globals.

Dan

> Any suggestions? Is this even the right area of code to look at? FWIW 
> I'm certainly able to make basic html errors, so it may not even be PHP 
> related.
> 
> ciao!
> 
> leam






More information about the talk mailing list