How the script is called affects the output???
Posted: Tue Sep 16, 2003 6:32 am
I'm working on a small PHP utility to enable easy editing of a javascript based menu system. The menu is stored in a file on the server. The utility reads the menu, alters it in some way, and write the result back to the menu file.
Using the functions that I have written (which use regular expressions and the preg family of functions), inserting a top level menu to be second in the list, the code would look like this: (note: I've ommitted most error checking for the sake of brevity)
All the individual functions work and the menu items are created, changed or deleted correctly.
The utility is using the Smarty template engine (Don't know how I survived before I started using that
), and on the form where the data for the menu is entered, there are several buttons which call javascript functions via the onclick event.
e.g. The code for a new menu item(my smarty delimiters are {%% & %%} - I like them)
Here is the problem, two menu items are inserted (at the correct place), but only one should have been. I've racked my brains going over the code, but it is all functioning correctly. I have pinned down the problem to how the script with the above PHP code is called.
If I replace the $_POST values with static values, fill out the form & submit (so the values from the form have no effect), the problem still occurs.
With the static values still in place, if I type out the URL: http://my_server/menutest/update_menu.php?action=new%20menu , (rather than submitting the form), then everything works correctly. Only one menu item is inserted into the file.
Is that strange or what?
Obviously, some of you guys would want to see other bits of code in order to comment, but I didn't want to overface everyone with loads of code straight away.
Does anyone have any ideas?? This wasn't a big utility - and at this rate it's easier to edit the menu manually (but for the intended users, that really isn't an option), but I'm starting to loose the will to live..
Any help is greatly appreaciated.
Jason.
Using the functions that I have written (which use regular expressions and the preg family of functions), inserting a top level menu to be second in the list, the code would look like this: (note: I've ommitted most error checking for the sake of brevity)
Code: Select all
$filename="menus/{$_POST["menu_to_edit"]}";
$menutext=read_menu_file($filename);
$newmenu=insert_menu_item($menutext,$_POST["new_menu_order"],$_POST["new_menu_name"],$_POST["new_link"],$image_file,$mouseover_image_file);
//$image_file & $mouseover_image_file have been added to from
//the $_POST values to include the image page
if(!output_menu_file($newmenu,$filename))
{
site_error("Failed to update menu");
}
else
{
site_ok("Menu updated");
}The utility is using the Smarty template engine (Don't know how I survived before I started using that
e.g. The code for a new menu item(my smarty delimiters are {%% & %%} - I like them)
Code: Select all
function new_menuitem(menutype)
{
if (confirm('Are you sure you want to create a new '+menutype+' menu?'))
{
document.formsї"menueditform"].action="{%%$update_target%%}?action=new%20menu"
document.formsї"menueditform"].submit()
}
}If I replace the $_POST values with static values, fill out the form & submit (so the values from the form have no effect), the problem still occurs.
With the static values still in place, if I type out the URL: http://my_server/menutest/update_menu.php?action=new%20menu , (rather than submitting the form), then everything works correctly. Only one menu item is inserted into the file.
Is that strange or what?
Obviously, some of you guys would want to see other bits of code in order to comment, but I didn't want to overface everyone with loads of code straight away.
Does anyone have any ideas?? This wasn't a big utility - and at this rate it's easier to edit the menu manually (but for the intended users, that really isn't an option), but I'm starting to loose the will to live..
Any help is greatly appreaciated.
Jason.