I need some help!
Why does the following code:
function buildDeleteForm($deleteUrl,$searchArray) {
print ("<form target=\"_self\" method=\"post\">
");
print ("<input type=\"hidden\" name=\"delUrl\" value=\"" . $deleteUrl . "\" />
");
print ("<input type=\"hidden\" name=\"url\" value=\"" . $searchArray . "\" />
");
print ("<input type=\"submit\" name=\"delete\" value=\"delete\" />
</form>
");
}
foreach ($urls as $url) {
$url = preg_replace('/\s+/', '', $url);
print("<tr><td>" . $url . "</td>");
$response = sendRestRequest($url,$type);
$status = $response['http_code'];
if ($status == 200) {
// build the form
print("<td class=\"result\"><img src=\"200.png\"></td><td class=\"right\">" . buildDeleteForm($url,$urllist) . "</td></tr>");
} elseif ($status == 404) {
print("<td class=\"result\"><img src=\"404.png\"></td><td class=\"right\"> </td></tr>");
} else {
print("<td class=\"result\"><img src=\"error.png\"></td><td class=\"right\">" . $status . "</td></tr>");
}
}
Produce this crazy HTML:
<tr>
<td>
http://someserver4017.site.com/resources/datacaches/xi50cache/xi50cache_RetailItemCommunication_se.LUT/sv_art_40101790
</td>
<form target="_self" method="post">
<input type="hidden" name="delUrl" value="http://someserver4017.site.com/resources/datacaches/xi50cache/xi50cache_RetailItemCommunication_se.LUT/sv_art_40101790" />
<input type="hidden" name="url" value="http://someserver4017.site.com/resources/datacaches/xi50cache/xi50cache_RetailItemCommunication_se.LUT/sv_art_40101790,http://someserver4018.site.com/resources/datacaches/xi50cache/xi50cache_RetailItemCommunication_se.LUT/sv_art_40101790,http://someserver4020.site.com/resources/datacaches/xi50cache/xi50cache_RetailItemCommunication_se.LUT/sv_art_40101790" />
<input type="submit" name="delete" value="delete" />
</form>
<td class="result">
<img src="200.png">
</td>
<td class="right">
</td>
</tr>
It's taken the form completely out of the table cell ... I could understand if it was just a css thing, but this is the actual generated source code being completely wierd. I know it's something simple that I just can't see and will look stupid - but hey I just want the thing to work :)
Because you are evaluating the function buildDeleteForm()
, which outputs a string to the user rather than simply returning it to be concatenated into the expression. Replace the multiple calls to print
in buildDeleteForm()
with a single return
statement.
Your buildDeleteForm
function is generating output rather than returning a string to be concatenated.
function buildDeleteForm($deleteUrl, $searchArray)
{
return '
<form target="_self" method="post">
<input type="hidden" name="delUrl" value="' . $deleteUrl . '" />
<input type="hidden" name="url" value="' . $searchArray . '" />
<input type="submit" name="delete" value="delete" />
</form>';
}
You are doing print instead of return, which means that it's printing the form before concatenating the table cell components and has nothing to concatenate because the function returns nothing. Do it like this instead:
function buildDeleteForm($deleteUrl,$searchArray) {
$html = '';
$html .= '<form target="_self" method="post">'."
";
$html .= '<input type="hidden" name="delUrl" value="' . $deleteUrl . '" />'."
";
$html .= '<input type="hidden" name="url" value="' . $searchArray . '" />'."
";
$html .= '<input type="submit" name="delete" value="delete" />'."
";
$html .= '</form>'."
";
return $html;
}
I've also changed the strings to take away all the backslashes, making it a bit more readable.