Page 1 of 1

loading an HTML form from PHP

Posted: Fri Aug 10, 2007 8:31 pm
by jambabe
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,

I have written a javascript which accepts input from the user, fills a form, and submits the data to a PHP script for processing. The PHP script generates an XML file(the XML representation of the form that he filled in). Once the XML file is generated, I want to present the user the form he just filled in (so, I want to reload the original HTML page) by clicking a button. My javascript is capable of reading in the generated XML file to fill the form, and I ideally want to perform this function when the user clicks on the button. Is there a way to do this from the PHP script? My javascript and PHP script are in two different files.

[syntax="html"]<html>
<header>
<script>
function genXmlFile() {

//create a form and submit using POST operation


}

function loadXmlFile() {
// opens the xml file and fills in the form
}
</script>
</header>

<body>
<div>
<input type="text" name="ModName" />
<input type="button" name="GenButton" value="Gen Xml File" onclick="genXmlFile" />

</div>
</body>
</html>
--------------------------

PHP script:[/syntax]

Code: Select all

<?php

// create the XML file

// post a button to the page which when clicked, will take the
// user back to the from above by calling the loadXmlFile()
// function.

?>

<html>
<body>
<INPUT type="button" id="EditData" value="Edit Data" onclick=?? />
</body>
</html>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Aug 10, 2007 9:52 pm
by s.dot
Submit the form to the processing script.. have it send the results back and use the onload event to trigger your javascript.

Although this is asynchrious javascript and xml (AJAX), so perhaps writing an ajax handler would be best for this.

Posted: Sat Aug 11, 2007 1:58 pm
by jambabe
Thanks for the reply.
That's what I'd like to do, and so far, I've managed to submit the data to the PHP script and generate the XML file. What I don't know how to do is how to pass enough information back from the PHP script to the Javascript script to trigger an event to indicate that a button was pushed. Is there a way to do that? My Javascript code and PHP script code are in two different files.