Jump to content

Recommended Posts

I have this xml file:

 

<?xml version="1.0" encoding="utf-8"?>

<links>

<category desc="XAML Related">

<link url="http://www.xamlong.com" desc="Xamlong.com" />

<link url="http://www.mobiform.com" desc="Mobiform" />

</category>

<category desc="Charlie Related">

<link url="http://jimslounge.com" desc="Jim's Lounge" />

<link url="http://spinach.com" desc="Spinach Blogs" />

</category>

</links>

 

I use simple xml to place the links inside inuput tags and display it:

 

<?php

function startElemHandler($parser, $name, $attribs) {

if (strcasecmp($name, "links") == 0) {

echo "<form id='linklist' action='processForm.php' method='POST'>\n";

echo "<table>\n";

}

if (strcasecmp($name, "category") == 0) {

$desc = $attribs['desc'];

echo "<tr>\n";

echo"<td><strong>$desc</strong></td>";

echo"</tr>\n<br>";

}

if (strcasecmp($name, "link") == 0) {

$url = $attribs['url'];

$desc = $attribs['desc'];

echo"<tr>";

$echoOut = "<td><input type='text' size='50' name='theLink' value='<a href=\"$url\" />'";

$echoOut .= "</a></td></tr>\n";

echo "$echoOut";

}

}

 

function endElemHandler($parser, $name) {

if (strcasecmp($name, "links") == 0) {

echo "<input name='submit' type='submit' value='Submit'>";

echo "</table>";

echo "</form>";

}

}

 

$parser = xml_parser_create();

xml_set_element_handler($parser, 'startElemHandler', 'endElemHandler');

xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);

$strXML = implode("",file("links3.xml"));

xml_parse($parser, $strXML);

xml_parser_free($parser);

?>

 

I submit to processForm.php for processing:

 

<?php

if (isset($_POST['theLink']))$theurl = $_POST['theLink'];

echo $theurl;

?>

 

What I want to do is to put the links contained in my xml file into a form so I can change the values and rewrite the xml file with the new values on submit. At this point I'm able to populate a form with the links from the xml file, to change values in any of the links, and to echo out the last value. I would like to be able to list all the new values when I process the form not just the last value. I think I can figure how rebuild the xml file on my own(maybe).

 

you can test here http://www.jimslounge.com/links3/processForm.php

processXML.zip

Link to comment
https://forums.phpfreaks.com/topic/274266-form-processing-problem/
Share on other sites

That does exactly the same, Timothy: Curly braces are completely optional when there's only one statement in the block.

 

There is one thing I do want to nitpick though, attaboy, and that is this line:

$strXML = implode("",file("links3.xml"));

 

This gives you the exact same end result as just using file_get_contents ().

 

In any case, for what I assume you're wondering about, in the absence of a proper question:

To retrieve all of the link values, you need to create an array out of the form inputs. This is done by adding square brackets to the end of the name of the input field, and to ensure that the association of the ID and value is kept you need to add the ID inside the brackets as well. Like this:

<input type="text" name="links[{ID}]" value="{VALUE}">

 

After you've done that, you need to loop over the $_POST['links'] array with foreach (), and compare the original values to the submitted ones. That'll give you the list of the changed values.

 

PS: Don't forget to validate the input, and escape the output.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.