html input names into an xml document using PHP -


this might simple question, i'm new php. need use html input tags same name , write entries xml document using php. of found uses same name in conjunction radio buttons, need these text input. agree array easiest way that, can't make array go xml file. want have multiple inputs of same name go xml because don't know how many authors users want put in xml. used clonenode method create more available entries. tried change name of input elements, doesn't seem work, , think easier of input post xml file. form html.

            <form action="generate.php" method="post" name="book">             <div id="wrap">                     <p id="author0">author's first name: <input class="firstinitial" type="text" name="firstinitial[]" placeholder="f" autocomplete="off" maxlength="1" size="1" ><input class="firstname" type="text" name="firstname[]" placeholder="irst name" autocomplete="off" /></input>                     author's middle initial: <input type="text" name="middleinitial[]" maxlength="1" placeholder="middle initial" autocomplete="off" />                     author's last name: <input class="firstinitial" type="text" name="lastname[]" placeholder="last name" autocomplete="off" /></p>             </div>                 <input type="button" value="add author" onclick="duplicate()"/>             <p>title: <input type="text" name="title" placeholder="title" /> </p>             <p>publisher: <input type="text" name="publisher" placeholder="publisher" /></p>             <p>city: <input type="text" name="city" placeholder="city" /></p>             <p>state: <input type="text" name="state" placeholder= "state" /></p>             <p>year: <input type="text" name="year" placeholder="year" /></p>             <!--change condition raio button-->             <p>condition: <input type="text" name="condition" /> (enter electronic if not in print)</p>             <p>first line:                  <input type="text" name="firstline" rows="4" cols="50" autocomplete="off" placeholder="first line" ></input>             </p>             <input type="submit" value="cite"></input>          </form> 

this php runs off of.

<?php header("location:start.html"); $xmldoc = new domdocument("1.0","utf-8"); $xmldoc->preservewhitespace = false; $xmldoc->load("booklist.xml"); $xmldoc->formatoutput=true;  $root = $xmldoc->firstchild; $book = $xmldoc->createelement("book"); $root->appendchild($book); $firstauthor=$xmldoc->createelement("authoreditor"); $firstauthor=$book->appendchild($firstauthor); $firstname=$_post["firstname"]; $firstinitial=$_post["firstinitial"]; $middleinitial=$_post["middleinitial"]; $lastname=$_post["lastname"]; for($x = 0; $x < count($firstname); $x++ ) {  $firstname=$xmldoc->createelement("firstname", $_post["firstname"]); $firstname=$firstauthor->appendchild($firstname); //add first initial first name  $firstinitial=$xmldoc->createelement("firstinitial", $_post["firstinitial"]); $firstinitial=$firstname->appendchild($firstinitial); $firstname->insertbefore( $firstinitial, $firstname->firstchild); //add rest of first name /*$firstname=$xmldoc->*/ /*$firstname->nodevalue=$_post['firstname'];*/ //add middle name $middlename=$xmldoc->createelement("middlename"); $middlename=$firstauthor->appendchild($middlename); //create place middle initial within authors name $middleinitial=$xmldoc->createelement("middleinitial", $_post["middleinitial"]); $middleinitial=$middlename->appendchild($middleinitial); //add last name $lastname=$xmldoc->createelement("lastname", $_post["lastname"]); $lastname=$firstauthor->appendchild($lastname); }  //creates title tag , inputs tag html says 'name="title"' $title=$xmldoc->createelement("title", $_post["title"]); $title=$book->appendchild($title);  $publisher=$xmldoc->createelement("publisher", $_post["publisher"]); $publisher=$book->appendchild($publisher);  $city=$xmldoc->createelement("city", $_post["city"]); $city=$book->appendchild($city);  $state=$xmldoc->createelement("state", $_post["state"]); $state=$book->appendchild($state);  $year=$xmldoc->createelement("year", $_post["year"]); $year=$book->appendchild($year);  $condition=$xmldoc->createelement("condition", $_post["condition"]); $condition=$book->appendchild($condition);  $firstline=$xmldoc->createelement("firstline", $_post["firstline"]); $firstline=$book->appendchild($firstline);  $xmldoc->save("booklist.xml"); ?> 

it's pretty simple, left of notes. want firstauthor of authors that's going change, need work. appreciated. thanks. after little more research, think got array working, still posts first author instead of everyone. updated code.

i figured out. needed bring in array afterall.html code <p id="author0">author's first name: <input class="firstinitial" type="text" name="firstinitial[]" placeholder="f" autocomplete="off" maxlength="1" size="1" ><input class="firstname" type="text" name="firstname[]" placeholder="irst name" autocomplete="off" /></input> author's middle initial: <input type="text" name="middleinitial[]" maxlength="1" placeholder="middle initial" autocomplete="off" /> author's last name: <input class="firstinitial" type="text" name="lastname[]" placeholder="last name" autocomplete="off" /></p> </div> <input type="button" placeholder="add author" value="add author" onclick="duplicate()" ></input> <!--use autocomplete="off" input isn't there on refresh or cite--> <p>title: <input type="text" name="title" placeholder="title" /> </p> <p>publisher: <input type="text" name="publisher" placeholder="publisher" /></p> <p>city: <input type="text" name="city" placeholder="city" /></p> <p>state: <input type="text" name="state" placeholder= "state" /></p> <p>year: <input type="text" name="year" placeholder="year" /></p> <!--change condition raio button--> <p>condition: <input type="text" name="condition" /> (enter electronic if not in print)</p> <p>first line: <input type="text" name="firstline" rows="4" cols="50" autocomplete="off" placeholder="first line" ></input> </p> <input type="submit" value="cite"></input> </form> php code `preservewhitespace = false; $xmldoc->load("booklist.xml"); $xmldoc->formatoutput=true;

$root = $xmldoc->firstchild; $book = $xmldoc->createelement("book"); $root->appendchild($book); //create first author tag for($x = 1; $x < count($_post["firstname"]); $x++ ) { $firstauthor=$xmldoc->createelement("authoreditor"); $firstauthor=$book->appendchild($firstauthor); $firstname=$xmldoc->createelement("firstname", $_post["firstname"][$x]); $firstname=$firstauthor->appendchild($firstname); //add first initial first name  $firstinitial=$xmldoc->createelement("firstinitial", $_post["firstinitial"][$x]); $firstinitial=$firstname->appendchild($firstinitial); $firstname->insertbefore( $firstinitial, $firstname->firstchild); //add middle name $middlename=$xmldoc->createelement("middlename"); $middlename=$firstauthor->appendchild($middlename); //create place middle initial within authors name $middleinitial=$xmldoc->createelement("middleinitial", $_post["middleinitial"][$x]); $middleinitial=$middlename->appendchild($middleinitial); //add last name $lastname=$xmldoc->createelement("lastname", $_post["lastname"][$x]); $lastname=$firstauthor->appendchild($lastname); } //creates title tag , inputs tag html says 'name="title"' $title=$xmldoc->createelement("title", $_post["title"]); $title=$book->appendchild($title);  $publisher=$xmldoc->createelement("publisher", $_post["publisher"]); $publisher=$book->appendchild($publisher);  $city=$xmldoc->createelement("city", $_post["city"]); $city=$book->appendchild($city);  $state=$xmldoc->createelement("state", $_post["state"]); $state=$book->appendchild($state);  $year=$xmldoc->createelement("year", $_post["year"]); $year=$book->appendchild($year);  $condition=$xmldoc->createelement("condition", $_post["condition"]); $condition=$book->appendchild($condition);  $firstline=$xmldoc->createelement("firstline", $_post["firstline"]); $firstline=$book->appendchild($firstline);  $xmldoc->save("booklist.xml"); 

?>`


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -