Jump to content

$_SERVER['PHP_SELF'] does not work via javascript


Fukushousha

Recommended Posts

Hello all.I have a problem. Up to now the calls to $_SERVER['PHP_SELF'] worked like a charm in any form in my website. Now I made something like ... a dynamic form generation. I am making the various forms by use of Javascript.LAter the javascript function is called inside a php script. Example of .js script:

function fillSetArt(div){	//we load the XML file into xmlAudioObj	xmlArtObj = loadXML(xmlArtObj,'artsoft.xml');		//this will be the function which will read the file and extract the data we need!	xmlArtObj.onreadystatechange = function() 			{					var text = '<form name="userSkills" id="userSkills" action="<?php echo $_SERVER[PHP_SELF]; ?>" method="POST">';

I added the form's declaration and well .. everything inside a javascript script which edits the inner html attribute of the DIV which I want to contain the various forms. The problem is that when I do it this way I get :Access forbidden!You don't have permission to access the requested object. It is either read-protected or not readable by the server.If you think this is a server error, please contact the webmaster.Error 403localhost06/18/08 11:23:07Apache/2.2.8 (Win32) DAV/2 mod_ssl/2.2.8 OpenSSL/0.9.8g mod_autoindex_color PHP/5.2.5And in the browser I can see that the error is thrown due to the PHPSELF call. Any idea how to get around this error?

Link to comment
Share on other sites

php is executed on the server not on the client side, what your script does is writes to form action <?php $_SERVER[php_SELF]; ?> not the actual script name because it is not executed.

Link to comment
Share on other sites

Yeah I know it is server side but I thought that it could work like that. Hm ... can anyone think of a workaround for this? Any way to both dynamically create the forms and be able to call the whole php script again whenever the php submit button is pressed?

Link to comment
Share on other sites

Let's say you want to create a form dynamically in JS. You don't know in advance what the form elements or their values will be. But you have a list of possibilities you can choose from. So store that information in JS variables, maybe even JS objects or arrays. Then when you need to create the form, you go get the data that corresponds to the page conditions.

Link to comment
Share on other sites

Ho! That worked very nice. Deirdre's dad that is what I did. Just stored it in xml so I could edit it easily and have some form of knowledge database, since the forms represent knowledge.My problem was solved by justsomeguy's very simple remark. I had no idea that <form ..... action="" .... > equals <form ..... action="<?php $_SERVER['PHP_SELF']?>" .... > . What I wanted to do worked now. Thanks!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...