IT Community - Software Programming, Web Development and Technical Support

form processing

This is a discussion on form processing within the PHP Programming forums, part of the Web Development category; please help correct the last 12 lines of this script. Hope the comments are adequate to inform what I want ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 08-24-2007, 01:31 AM
Archimedees Archimedees is offline
D-Web Trainee
 
Join Date: Aug 2007
Posts: 15
Archimedees is on a distinguished road
Default form processing

please help correct the last 12 lines of this script. Hope the comments are adequate to inform what I want to achieve. Thanks.

Quote:
<?php

//================================================== ===========================
// read_contents(): function to read content of a page.conf-File and parse it
// into the proper data structure.
//================================================== ===========================
function read_contents($strFilename )
{

//List for storing the parsed lines
$arParsedLines = array();

//read file
$nFileHandle = fopen($strFilename, "r+");

while (!feof($nFileHandle))
{
//echo "--------------------------------------------------------------------<br>\n";
$strCurrentLine = fgets ( $nFileHandle, 4096 );

if (strlen($strCurrentLine) < 7)
{
continue;
}//end if (strlen($strCurrentLine) < 7)

//echo "strCurrentLine enthält: ->".$strCurrentLine."<-<br>\n";

//echo "Datenstruktur wird angelegt: <br>\n";
$arThisLine = array("url" => "", "email" => "", "size" => "", "command" => "", "active" => true);

//echo "Datenstruktur arThisLine: <br>\n";
//print_r($arThisLine);

//echo "\n<br>suche nach hash<br>\n";
$nPosOfHash = strpos($strCurrentLine, "#");

if (!($nPosOfHash === false))
{
//echo "HASH gefunden: Position: ".$nPosOfHash."<br>\n";
$arThisLine["active"] = false;

$strCurrentLine = substr ( $strCurrentLine, 1);

}//end if (!($nPosOfHash === false))
else
{
//echo "Kein HASH in der aktuellen Logzeile gefunden<br>\n";
}//end else (!($nPosOfHash === false))

//echo "strCurrentLine ist jetzt: ->".$strCurrentLine."<-<br>\n";

$arTemp = explode("\t", $strCurrentLine);

//echo "Ergebnis von Explode: <br>\n";
//print_r($arTemp);
//echo "\n<br>ende<br>\n";

$arThisLine["url"] = $arTemp[0];
$arThisLine["email"] = $arTemp[1];
$arThisLine["size"] = $arTemp[2];
$arThisLine["command"] = $arTemp[3];

//echo "Datenstruktur arThisLine: <br>\n";
//print_r($arThisLine);
//echo "\n<br>ende<br>\n";

array_push($arParsedLines,$arThisLine);

}//end while (!feof($nFileHandle))

return $arParsedLines;
}//end read_contents()


//================================================== ===========================
?>

<html>
<head>
<title>Display</title>
<body>
<p>Display Active Checkboxes<p>
<pre>
Content of Array $_GET:
<?php
//================================================== ===========================
//get available Keys out of array

$arOurKeys = array_keys($_GET);

//for each key that matches "active_<number>"
//we want to do something

/*
$active = $_GET['active_.$key.'];
if($arLine["active"]==true)
{
echo $active.": ".$_GET[$active]."<br>\n";
}
*/

print_r($_GET);


echo "our keys:\n";
print_r($arOurKeys);


/*
$nArrayLength = count($arOurKeys);
for ($i=0; $i<$nArrayLength; $i++)
{
echo "Loop Variable i is: ".$i."\n";
echo $arOurKeys[$i];
echo "\n";
}//end for ($i=0; $i<$nArrayLength; $i++)
*/

$arLineNumbers = array();

foreach($arOurKeys as $strArrayElement)

{

echo "Value of strArrayElement is: ".$strArrayElement." ";
if (strncmp($strArrayElement, "active_", 7 ) == 0)
{
echo "we have a match ";
$strNumber = str_replace ( "active_", "", $strArrayElement);
echo "extracted Line-Number: ".$strNumber."\n";
array_push($arLineNumbers, $strNumber);
}//end if (strncmp($strArrayElement, "active_", 7 ) == 0)
}//end foreach($arOurKeys as $strKey)

print_r ($arLineNumbers, true);

//read the page.conf here into Array $arParsedLines

$arParsedLines = read_contents("page.conf");
print_r($arParsedLines);

//read the page.conf here into Array $arParsedLines

foreach ($arParsedLines as $nValue)
{
echo "$nValue["active"] = false";
}
print_r($nValue);
//mark all lines inside $arParsedLines with active=false

array_walk($arLineNumbers);

echo "$arParsedLines["active"] = true";

print_r($arLineNumbers);
//walk through the Array $arLineNumbers
//for each Line-Number in that array:
//set active=true for the corrosponding line the Array $arParsedLines
?>
</pre>
</body>
</html>
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-24-2007, 01:51 AM
Archimedees Archimedees is offline
D-Web Trainee
 
Join Date: Aug 2007
Posts: 15
Archimedees is on a distinguished road
Default Re: form processing

Forgot to include the initial form script. Thanks


Quote:
<html>
<head>
</head>
<body>
<?php

//List for storing the parsed lines
$arParsedLines = array();

//read file
$nFileHandle = fopen("pag.conf", "r+");

while (!feof($nFileHandle))
{
//echo "--------------------------------------------------------------------<br>\n";
$strCurrentLine = fgets ( $nFileHandle, 4096 );

if (strlen($strCurrentLine) < 7)
{
continue;
}//end if (strlen($strCurrentLine) < 7)

//echo "strCurrentLine enthält: ->".$strCurrentLine."<-<br>\n";

//echo "Datenstruktur wird angelegt: <br>\n";
$arThisLine = array("url" => "", "email" => "", "size" => "", "command" => "", "active" => true);

//echo "Datenstruktur arThisLine: <br>\n";
//print_r($arThisLine);

//echo "\n<br>suche nach hash<br>\n";
$nPosOfHash = strpos($strCurrentLine, "#");

if (!($nPosOfHash === false))
{
//echo "HASH gefunden: Position: ".$nPosOfHash."<br>\n";
$arThisLine["active"] = false;

$strCurrentLine = substr ( $strCurrentLine, 1);

}//end if (!($nPosOfHash === false))
else
{
//echo "Kein HASH in der aktuellen Logzeile gefunden<br>\n";
}//end else (!($nPosOfHash === false))

//echo "strCurrentLine ist jetzt: ->".$strCurrentLine."<-<br>\n";

$arTemp = explode("\t", $strCurrentLine);

//echo "Ergebnis von Explode: <br>\n";
//print_r($arTemp);
//echo "\n<br>ende<br>\n";

$arThisLine["url"] = $arTemp[0];
$arThisLine["email"] = $arTemp[1];
$arThisLine["size"] = $arTemp[2];
$arThisLine["command"] = $arTemp[3];

//echo "Datenstruktur arThisLine: <br>\n";
//print_r($arThisLine);
//echo "\n<br>ende<br>\n";

array_push($arParsedLines,$arThisLine);

}//end while (!feof($nFileHandle))


//echo "angesammelte Liste:<br>\n";
//print_r($arParsedLines);
?>

<form name="urllist" action="display.php" method="get">
<table border=1>
<tr>
<th></th>
<th></th>
<th>URL</th>
<th>Notify-Email</th>
<th>Size</th>
<th>Command</th>
</tr>

<?php
foreach($arParsedLines as $key => $arLine)
{
echo "<tr>\n";
echo " <td></td>\n";
echo " <td><input type=\"checkbox\" name=\"active_".$key."\" value=\"active\"";
if ($arLine["active"]==true)
{
echo "checked";
}
echo "></td>\n";
echo " <td>".$arLine["url"]."</td>\n";
echo " <td>".$arLine["email"]."</td>\n";
echo " <td>".$arLine["size"]."</td>\n";
echo " <td>".$arLine["command"]."</td>\n";
echo "</tr>\n";
}//end foreach($arParsedLines as $arLine)
?>
</table>
<input type="submit" name="uebernehmen" value="uebernehmen">
</form>
</body>
</html>
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-30-2007, 02:51 AM
ragavraj ragavraj is offline
D-Web Programmer
 
Join Date: Feb 2007
Posts: 92
ragavraj is on a distinguished road
Default Re: form processing

hi Archimedees

could u give me a pag.conf file conent and also give a

entire coding because first code u tried a through read contents

function second one u tried with out function which one is updated script

Thanks
R.Rajan
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-04-2007, 03:39 AM
Archimedees Archimedees is offline
D-Web Trainee
 
Join Date: Aug 2007
Posts: 15
Archimedees is on a distinguished road
Default Re: form processing

Thanks Rajan,

I was able to solve this problem. Can't post page.conf here though because of security reasons. It contains real company urls plus email addresses. I've posted a new problem which concerns adding new input to page.conf from user input in a html form.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date/time stamp a form field as the form is submitted itbarota HTML, CSS and Javascript Coding Techniques 1 02-06-2008 10:16 PM
Date/Time stamp a form field as the form is submitted itbarota HTML, CSS and Javascript Coding Techniques 2 01-17-2008 08:47 PM
How can I clear the form field values after the user has submitted the form for clien itbarota HTML, CSS and Javascript Coding Techniques 1 11-01-2007 11:39 PM
How can I pass a hidden value to a form and submit that form when a text link is clic itbarota HTML, CSS and Javascript Coding Techniques 1 10-17-2007 08:07 AM
What is batch processing? leoraja8 Database Support 1 09-07-2007 04:35 AM


All times are GMT -7. The time now is 03:11 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0