Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Need help with a form, using php to create xml
Old 10-10-2010, 10:54 PM Need help with a form, using php to create xml
Junior Talker

Posts: 2
Trades: 0
Hello all, I am trying to create an interface that will allow someone other than myself to update an xml file which stores company contact info. I have the xml getting pulled in to another page which runs the google maps api to create markers, windows, etc. I would like to append rather than create new every time.

I've been reading up on w3c and browsing tutorials for a few days, but I'm sort of new to this (both php and javascript which I had to use for the google api), so please forgive my ignorance. I'm probably going to have to adjust my xml structure as right now all the address information is stored in a CDATA section. I know how to parse the xml to display it if I were to change the address info to attributes or even child elements, however if there is a simple way to not do this, it would keep me from having to change my js to get the map working.

My xml structure is basically like this:
Code:
<markers>
<marker lat="45.4654521" lng="99.9999" company="McDonalds">
 <infowindow>
  <[CDATA [
    <h1>McDonalds</h1><br />
    123 Street Ave<br />
    City, ST 99999<br />
    <a href="www.google.com">google!</a>
    ]]>
  </infowindow>
 </marker>
</markers>
My php script to parse and display the company name of existing entries:
Code:
<?php
$xml = simplexml_load_file("rp2.xml");

foreach($xml->marker as $marker)
  {
 
  echo "<table>
  <tr>
  <td width='10%' class='tdnavtitle'>" . $marker['company'] . "</td></tr>
  </table>";
  }
 ?>
And my form, which I know is missing an onsubmit() and the action is blank (missing because I don't know what to do at this point):
Code:
	<form id="form1" name="form1" method="post" action="">
	  <table width="100%" border="1">
	    <tr>
		 <td colspan="2" bgcolor="#CCCCCC">Contacts Info Input Form</td>
		</tr>
		<tr>
		 <td></td>
		 <td></td>
		</tr>
		<tr>
		 <td width="12%"><strong>Company Name:</strong></td>
		 <td width="88%"><label>
		   <input name="name" type="text" id="name" />
		   </label></td>
		</tr>
		<tr>
		 <td width="12%"><strong>Street Address:</strong></td>
		 <td width="88%"><label>
		   <input name="name" type="text" id="street" />
		   </label></td>
		</tr>
		<tr>
		<td width="12%"><strong>City:</strong></td>
		 <td width="88%"><label>
		   <input name="name" type="text" id="city" />
		   </label></td>
		</tr>
	  </table>
	</form>
I guess what I am looking for is:
How do I append my xml file from the php script, when the user has put data in the required fields, and clicks submit? Any help would be very appreciated.
Prime8 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-11-2010, 03:04 PM Re: Need help with a form, using php to create xml
3nomore's Avatar
Experienced Talker

Posts: 40
Name: Felipe
Trades: 0
I am sorry, but I do not fully understand what is it that you want to do, you want to keep the current xml data plus the new data or do you want to append to the previews data the new one?
3nomore is offline
Reply With Quote
View Public Profile Visit 3nomore's homepage!
 
Old 10-11-2010, 05:57 PM Re: Need help with a form, using php to create xml
Junior Talker

Posts: 2
Trades: 0
Basically, I want to make this:
Code:
<markers>
<marker lat="45.4654521" lng="99.9999" company="McDonalds">
 <infowindow>
  <[CDATA [
    <h1>McDonalds</h1><br />
    123 Street Ave<br />
    City, ST 99999<br />
    <a href="www.google.com">google!</a>
    ]]>
  </infowindow>
 </marker>
</markers>
Into this:
Code:
<markers>
<marker lat="45.4654521" lng="99.9999" company="McDonalds">
 <infowindow>
  <[CDATA [
    <h1>McDonalds</h1><br />
    123 Street Ave<br />
    City, ST 99999<br />
    <a href="www.google.com">google!</a>
    ]]>
  </infowindow>
 </marker>
<marker lat="45.4654521" lng="99.9999" company="Taco Bell">
 <infowindow>
  <[CDATA [
    <h1>Taco Bell</h1><br />
    321 Ave St<br />
    City, ST 99999<br />
    <a href="www.yahoo.com">yahoo!</a>
    ]]>
  </infowindow>
 </marker>
</markers>
when the user enters the data into the form, and clicks submit. I think this is called appending. If I have to change the format of my xml I can, although I would prefer not to if it can be helped, as its already taken me a good 2 weeks to get the google maps api to read the xml and create the markers and infowindows.
Prime8 is offline
Reply With Quote
View Public Profile
 
Old 10-11-2010, 06:29 PM Re: Need help with a form, using php to create xml
3nomore's Avatar
Experienced Talker

Posts: 40
Name: Felipe
Trades: 0
I see, then yes, you have to append your data.

Steps are basically:
- Loading your current xml
- Adding new data
- Recreating the xml with the new parts

I know it sounds silly, but that those are the basic steps.

You are using simplexml_load_file() this should give you an object from where you can start.

Do you have a function to create the xml? or do you start from a current xml?
If you don't have a function to create the xml, that is where you should start, once you have this function, all you need to do is recreate the new xml with the new information.

You can start with this functions: http://www.php.net/manual/en/book.xmlwriter.php

And then we can guide you if you run into trouble.

I think I may have a function that does that already, if I find it I will post it here so you can start from there.

Regards.
__________________
Play the stock market for real

Please login or register to view this content. Registration is FREE
3nomore is offline
Reply With Quote
View Public Profile Visit 3nomore's homepage!
 
Reply     « Reply to Need help with a form, using php to create xml
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.61742 seconds with 12 queries