flipping $_Post or input names and values
Posted: Sat Aug 19, 2006 11:10 pm
I feel bad for two post in one day but I've searched pretty extensively for the answer to this question elsewhere and I haven't quite found an answer. feyd tried to answer it for me but I accidently eplained it improperly... and I can't pay $500 to have him take another shot...
Basically I have multiple "suggestions" on a page and I want two buttons tied to each suggestion... a ++ button and a -- button. What is the most simple and secure way to do this? Say I have this code:
then I can just put
in the header of the next page and everything will be fine... BUT (and the but of the week for me) I don't ever want the user to see the $value['id'] cause it's meaningless to them and then they wont know what the buttons do. If I switch the value and name field of the submit then I have to walk through the entire $_POST looking for one that points to ++ or -- and when the number of suggestions increases that becomes dumber and dumber... I had a moment of brilliance and thought I could just array_flip($_POST) but I dont think that works... and furthermore that'll mess with my other $_POST vars... if only i could mask over the value of those submit buttons with a different value...
there's got to be a really simple elegant solution to this common problem right?
Thanks so much.
-Tommy
Basically I have multiple "suggestions" on a page and I want two buttons tied to each suggestion... a ++ button and a -- button. What is the most simple and secure way to do this? Say I have this code:
Code: Select all
<form action="index.php?page=<?php echo $page ?>" method="post">
<?php foreach($suggestions as $key => $value){ ?>
<div align="center" class="ranking">
<?php echo '<input type="submit" value="'.$value['id'].'" name="++"/>'; ?>
<div class="votes">
<?php
echo $value['rating'];
?>
</div>
<?php echo '<input type="submit" value="'.$value['id'].'" name="++"/>'; ?> </div>
<?php } ?>
</form>Code: Select all
if($_POST['++']){
bumpSuggestion(sanitize_int($_POST['++']),1);
}
else if($_POST['--']){
bumpSuggestion(sanitize_int($_POST['--']),-1);
}there's got to be a really simple elegant solution to this common problem right?
Thanks so much.
-Tommy