By Kobus on
Hi,
I am trying to create a simple page that will update a table in the database. When I create the page outside of Drupal, I am getting the desired result. When I paste it inside a Drupal node with PHP code enabled, it is as if the submit button never gets set.
What could be the problem? Is this not possible to do in Drupal? The only possible reason I could see there is the use of $PHP_SELF, but I have hardcoded it to "/node/14" and it still didn't work... I would really appreciate some help.
Here is the code:
<?php
function listing_list_nodes() {
$output = "";
//$query = "SELECT n.title as title, n.nid as nid from {node} n where n.type='listing'";
//$result = db_query($query);
//while ($item = db_fetch_array($result)) {
// $output .= " <option>" . $item['title'] . " - " . $item['nid'] . "</option>\n";
//}
$output .= "<option>Blah Blah</option>\n";
return $output;
}
function listing_generate_vote_form() {
$output = "<p>This form is used to update the YES and NO votes for a particular company listing, as received by SMS.</p>\n";
$output .= "<form name=\"voter_updater\" action=\"" . $PHP_SELF . "\" method=\"post\">\n";
$output .= " <select name=\"listing_node_list\">\n";
$output .= listing_list_nodes();
$output .= " </select>\n";
$output .= " <p>Number of YES votes:<br><input id=\"listing_yes_votes\" type=\"text\" maxlength=\"4\" size=\"4\" value=\"" . $listing_yes_votes . "\" name=\"listing_yes_votes\"></p>\n";
$output .= " <p>Number of NO votes:<br><input id=\"listing_no_votes\" type=\"text\" maxlength=\"4\" size=\"4\" value=\"" . $listing_no_votes . "\" name=\"listing_no_votes\"></p>\n";
$output .= " <input id=\"listing_submit_votes\" type=\"submit\" name=\"listing_submit_votes\" value=\"Update votes!\">\n";
$output .= "</form>\n";
return $output;
}
function listing_update_votes($a, $b, $c) {
$output = "<p>The vote updates have been submitted as follows:</p>\n";
$output .= "<li>Node that was updated:" . $a . "</li>\n";
$output .= "<li>The number of YES votes added: " . $b . "</li>\n";
$output .= "<li>The number of NO votes added: " . $c . "</li>\n";
// TODO: Actual write to the DB
return $output;
}
if (isset($listing_submit_votes)) {
print listing_update_votes($listing_node_list, $listing_yes_votes, $listing_no_votes);
}
else {
print listing_generate_vote_form($listing_yes_votes, $listing_no_votes);
}
?>
Comments
Where does $listing_submit_votes come from?
You use it to decide if you should save the information or display the form but it appears to never be set.
listing_submit_votes
That (listing_submit_votes) is the name and ID of the submit button of the form. It gets set by clicking the submit button.
The code as is works correctly when not within Drupal (you can test it if you wish). It only breaks when I put it into a Drupal page.
Thanks for the response.
-- Kobus
Try using $_POST
You script is expecting the values in $_POST to be exported as globals and I think that is disabled inside Drupal.
Instead of $listing_submit_votes try $_POST['listing_submit_votes']
Thanks!
Thank you, nevets. That may well solve the problem. I will try that!
-- Kobus