Jump to content

Using a form to update the same page - all in php and other veriables


dave007

Recommended Posts

I have xml files for a whole bunch of data. I have managed to get them into a nice format and showing on an html page fine. I can even go backwards and forwards between xml files. To do this I simply use a $_GET['rec'] variable.

 

However, I've been trying to ALSO have things update on the page when the user selects (preferably just clicks on) an item in a <select> tag - populated from the XML file.

 

Below is my latest attempt at this (with the population of the <select>):

 

echo "<form id=v2p method=\"POST\"><select size = 5 onclick=\"javascript:document.v2p.submit();return false;\">";

 

$vars = $xmlDoc->getElementsByTagName('var');

foreach($vars as $var)

{

$varname = $var->getElementsByTagName('vaname')->item(0)->nodeValue;

echo "<option value=$varname>$varname</option>";

}

echo "</select></form>";

echo "<br/>";

$var2plot = $_POST['v2p'];

echo "<a>$var2plot</a>";

 

I get an "Undefined index: v2p" error on line 75 ($var2plot = $_POST['v2p']; ):

 

Please could someone show me a nice way to make it work...

 

Thanks in advance,

Dave

The POST array uses field NAMES for its indexes you haven't defined any i.e.

// $_POST['v2p'] will contain the value of the following field after form submission i.e. 123
<input type="text" name="v2p" id="xyz" value="123" />

I think this is a problem with sending two GET requests... I've managed to make the form update one of the

<form name="VarForm" action="' . $_SERVER['PHP_SELF'] . '" method="GET"><select name = "v2p" size=5 OnChange="VarForm.submit();">';

 

but now the 'rec' variable is lost... please could someone save my hair from all being pulled out.

 

Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.