tomindo Posted December 7, 2010 Share Posted December 7, 2010 <form action="jvs.php" method="post"> <input type="checkbox" name="box" value="haa"> <input type="submit" value="submit"> </form> <?php echo $_POST['name']; ?> hi all How can I get the value of name which is box through post or get from the code Link to comment https://forums.phpfreaks.com/topic/220958-get-the-value-of-attribute-name-through-post-or-get/ Share on other sites More sharing options...
AbraCadaver Posted December 7, 2010 Share Posted December 7, 2010 echo $_POST['box']; Link to comment https://forums.phpfreaks.com/topic/220958-get-the-value-of-attribute-name-through-post-or-get/#findComment-1144110 Share on other sites More sharing options...
tomindo Posted December 7, 2010 Author Share Posted December 7, 2010 thanks Shawn but I tried to echo box not haa as you mentioned, not sure if able to do that Link to comment https://forums.phpfreaks.com/topic/220958-get-the-value-of-attribute-name-through-post-or-get/#findComment-1144116 Share on other sites More sharing options...
AbraCadaver Posted December 7, 2010 Share Posted December 7, 2010 thanks Shawn but I tried to echo box not haa as you mentioned, not sure if able to do that I have no idea what you mean. Given the code that you posted, if you use my echo instead of yours and you CHECK the box and SUBMIT the form you will see haa outputted. Assuming that the PHP code is located in jvs.php. What are you wanting? Link to comment https://forums.phpfreaks.com/topic/220958-get-the-value-of-attribute-name-through-post-or-get/#findComment-1144119 Share on other sites More sharing options...
tomindo Posted December 7, 2010 Author Share Posted December 7, 2010 I want name="box" to pass when I submit. In other words, I want to pass value "box" not "haa" when clicking submit thanks you Link to comment https://forums.phpfreaks.com/topic/220958-get-the-value-of-attribute-name-through-post-or-get/#findComment-1144128 Share on other sites More sharing options...
tomindo Posted December 7, 2010 Author Share Posted December 7, 2010 sorry , I want to pass both "haa" and "box" . I want to reuse "box" , of course "haa" as well. Yeah, I know "echo $_POST['box'] " will pass "haa". So how to pass "box"? Link to comment https://forums.phpfreaks.com/topic/220958-get-the-value-of-attribute-name-through-post-or-get/#findComment-1144133 Share on other sites More sharing options...
AbraCadaver Posted December 7, 2010 Share Posted December 7, 2010 I want name="box" to pass when I submit. In other words, I want to pass value "box" not "haa" when clicking submit thanks you <input type="checkbox" name="name" value="box"> But this is probably not what you want. What are you trying to accomplish exactly? Link to comment https://forums.phpfreaks.com/topic/220958-get-the-value-of-attribute-name-through-post-or-get/#findComment-1144134 Share on other sites More sharing options...
tomindo Posted December 7, 2010 Author Share Posted December 7, 2010 right , that is not I want. I want to reuse "box" , of course "haa" as well. Yeah, I know "echo $_POST['box'] " will pass "haa". So how to pass "box"? thanks Link to comment https://forums.phpfreaks.com/topic/220958-get-the-value-of-attribute-name-through-post-or-get/#findComment-1144135 Share on other sites More sharing options...
AbraCadaver Posted December 7, 2010 Share Posted December 7, 2010 right , that is not I want. I want to reuse "box" , of course "haa" as well. Yeah, I know "echo $_POST['box'] " will pass "haa". So how to pass "box"? thanks You can't pass two values for one control. Ignore what you are trying to do and break it down in more simple terms. There is probably a way but this isn't it. Link to comment https://forums.phpfreaks.com/topic/220958-get-the-value-of-attribute-name-through-post-or-get/#findComment-1144137 Share on other sites More sharing options...
volatileboy Posted December 7, 2010 Share Posted December 7, 2010 If you know the incoming variable (box) why do you need to pass it to reuse it when you already know what it is Link to comment https://forums.phpfreaks.com/topic/220958-get-the-value-of-attribute-name-through-post-or-get/#findComment-1144138 Share on other sites More sharing options...
tomindo Posted December 7, 2010 Author Share Posted December 7, 2010 you think we can add more control ? Link to comment https://forums.phpfreaks.com/topic/220958-get-the-value-of-attribute-name-through-post-or-get/#findComment-1144141 Share on other sites More sharing options...
requinix Posted December 7, 2010 Share Posted December 7, 2010 It's best if you know something coming from the form - whether it's "box" or "data" or whatever. foreach ((array)$_POST["data"] as $name => $value) { echo "{$name} = {$value} \n"; } (It's generally not good to loop on $_POST itself.) Link to comment https://forums.phpfreaks.com/topic/220958-get-the-value-of-attribute-name-through-post-or-get/#findComment-1144153 Share on other sites More sharing options...
tomindo Posted December 7, 2010 Author Share Posted December 7, 2010 thanks guys btw, hey requinix just wondering why did you put curly brackets around $name and $value while without them the result are the same Link to comment https://forums.phpfreaks.com/topic/220958-get-the-value-of-attribute-name-through-post-or-get/#findComment-1144186 Share on other sites More sharing options...
requinix Posted December 7, 2010 Share Posted December 7, 2010 thanks guys btw, hey requinix just wondering why did you put curly brackets around $name and $value while without them the result are the same Because I prefer to. Easier to read. String parsing Link to comment https://forums.phpfreaks.com/topic/220958-get-the-value-of-attribute-name-through-post-or-get/#findComment-1144197 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.