0

I have a couple of input boxes where the user will be entering his/her data .
for example:

Name:-------------
Fathers name:-----------
mothers name:------------

when the user enters the data , i need the xml to be generated something like this

<family>
<name> users name </name>
<fname> fathers name </fname>
<mname> mothers name </mname>
</family>

4
Contributors
6
Replies
9
Views
7 Years
Discussion Span
Last Post by rahul8590
0

Hey,
You need to have a HTML form to 'POST' (Submit) the form and a PHP script to generate the file.
The HTML side
call this form.html or something

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Form Page</title>
</head>

<body>
<form name="form1" action="generate.php" method="post">
Name: <input name="name" type="text" /><br/>
Mothers Name: <input name="mname" type="text" /><br/>
Fathers Name: <input name="fname" type="text" /><br/>
<input name="submit" type="submit" value="Submit" />
</form>
</body>
</html>

Then the PHP code to generate the XML
call this generate.php (As per our action in the HTML form)

<?php
header('Content-type: text/xml');//Tell the browser it's an XML document
ob_start();
echo '<?xml version="1.0"?'.'>'."\n";//We have to break up the XML closing tag because [?]> is the closing tag for PHP
echo "<family>
<name>{$_POST['name']}</name>
<fname>{$_POST['fname']}</fname>
<mname>{$_POST['mname']}</mname>
</family>";
?>
0

that was great .. it really helped me . but supposedly the input is dynamic in nature . i mean if i dont know the number of name inputs , in that case how do i generate the xml data out of it.

0

here is a basic example of wat i meant by dynamic
the below is a basic form meant ti generate the no of name fields as inputed

<form action="redirect_new.php" method="post">
Name: <input type="text" name="yourname" maxlength="150" /><br />
<input type="submit" value="Submit" style="margin-top: 10px;" />
<?php
$val = $_POST['yourname'];
setcookie("name",$val,time()+3600);

for ( $i = 1; $i <= $val ; $i++)
{
?>
<form action="redirect1.php" method="post">
Name: <?php echo $i ?>  <input type="text" name=<?php echo "\"yourname"."$i\""   ?> maxlength="150" /><br />
<?php

} 
?>
<input type="submit" value="Submit" style="margin-top: 10px;" />

the above is the equivalent php code . Now in this case since we dont know the number of name fields to be entered , how do i generate the xml data for this ?

0

firstly srry for late reply , for some reason i aint getting notification of reply for the threads i started in daniweb , dunno y.

that is an awesome link .. very helpful .

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.