Jump to content

Store a variable at form submit


yoshida

Recommended Posts

Hi folks, I'm facing a bit of a snag here.I'm making a CMS manpage to alter the content for my website. I divided the workload into chunks to keep it all manageable, so far I have template related database info, a news manpage, and a management page to add and alter 'html' pages.Each manpage is a form or a set of forms, which gets loaded into a DIV using the XmlHttpRequest (think 'AJAX'). So I have one index.html, and a menu decides which variable is used to load the related PHP script.I have the function that loads stuff check if a variable already exists, and if not it uses a default value.

	if (!serverPage) {		var serverPage = 'tempmanpage.php';	}

I tested this CMS manpage succesfully for the first script, tempmanpage.php (which manages information loaded for the template).When I use AJAX to load the script called defmanpage.php, the page to manage default HTML pages stored into the database, it shows as expected. I embedded a form with a dropdown menu to decide whether I want to create a new page or alter an existing one. A textarea is opened containing the HTML code for the page I want to alter or containing nothing at all if I want to create a new page. The action for this form is obviously index.html, because I want to reload my PHP script to create the textbox and fill it with the desired info. The problem is my javascript uses the default value (tempmanpage.php) and not the value for the last visited page (defmanpage.php).So the question is quite simple: I want my index.html to load a specific page when I click Submit. Is there any way to do so? Do I have to migrate my form from PHP to Javascript, and if so, what would be the best approach? I'm far more familiar with PHP than with Javascript.

Link to comment
Share on other sites

[...]The action for this form is obviously index.html, because I want to reload my PHP script to create the textbox and fill it with the desired info. The problem is my javascript uses the default value (tempmanpage.php) and not the value for the last visited page (defmanpage.php) [...]
I haven't used PHP but from other server-side scripting I would say your index.html could become a server-side scripted (php?) page, so that within it, you could generate that javascript function with the appropriate default value of that variable:
if (!serverPage) {	var serverPage =  (php to write name of correct page, based on what was submitted)}

Link to comment
Share on other sites

Sounds like a plan, but can't I let Javascript fetch the post info instead? Can it be used again by my PHP script?My javascript is in an external .js script.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...