prallen Posted March 9, 2010 Share Posted March 9, 2010 Just as the title says, I am creating an image rating system - somewhat like hotornot.com. I have 10 radiobuttons numbered 1-10 and i need them to submit their own value using $_POST when one of the radio buttons is clicked. I'm not sure how to go about this... I see a lot of sites like this using Javascript. Is there any way around using javascript? what can I do? prallen is online now Add to prallen's Reputation Report Post Reply With Quote Quote Link to comment https://forums.phpfreaks.com/topic/194584-need-to-submit-a-value-on-radiobutton-click-php-picture-rating-system/ Share on other sites More sharing options...
lupld Posted March 9, 2010 Share Posted March 9, 2010 the only way I know is to use javascript to submit the form, which isn't too hard to do, search around in google. each radiobutton will have something like onclick="submit();" and then you will have a javascript function like function submit() { this line of code would submit your specified form with the data as entered } making it post the form, and then obviously you just put method="post" in the form tag to make it post instead of get. Quote Link to comment https://forums.phpfreaks.com/topic/194584-need-to-submit-a-value-on-radiobutton-click-php-picture-rating-system/#findComment-1023359 Share on other sites More sharing options...
lupld Posted March 9, 2010 Share Posted March 9, 2010 if you really need me to I can look up the specific javascript, let me know... noone ever helps me on here, so I should at least try and fill in the gaps. Quote Link to comment https://forums.phpfreaks.com/topic/194584-need-to-submit-a-value-on-radiobutton-click-php-picture-rating-system/#findComment-1023361 Share on other sites More sharing options...
prallen Posted March 9, 2010 Author Share Posted March 9, 2010 thanks for trying to help lupld. I see stuff like that when i look at source code for other websites. the only problem is i need the page to refresh, show a new random picture, update the ratings to the db, and then show the previous picture in the upper left corner of the page. How would i go about updating the database and refreshing the page with the previous picture information? Quote Link to comment https://forums.phpfreaks.com/topic/194584-need-to-submit-a-value-on-radiobutton-click-php-picture-rating-system/#findComment-1023364 Share on other sites More sharing options...
lupld Posted March 9, 2010 Share Posted March 9, 2010 cause I have nothing better to do right now, try this. <script type="text/javascript"> function submit() { document.forms["myform"].submit(); } </script> <form id="myform" method="post" action="action.php"> and your radio buttons in the form will look like this <input type="radio" onclick="submit();" value="7" name="picrating" /> basically, add onclick="submit();" to your radio buttons, add id="myform" to the form tag (you can change myform, just make sure you change it EVERYWHERE it occurrs), and copy that javascript into your header. I don't think you need a submit button either, as the javascript seems to cover for it, if it doesn't work try putting in a submit button and adding style="display:none;" to it so it doesn't appear on the page. You may be shy about using javascript, but it posts the data the same way as if the user clicked a submit button, and it plays well in php. No, there isn't really a php thing you can do for this, as php is a server side language, and javascript is a client side language. I've narrowed the javascript down as easy as I think I can for you. Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/194584-need-to-submit-a-value-on-radiobutton-click-php-picture-rating-system/#findComment-1023368 Share on other sites More sharing options...
lupld Posted March 9, 2010 Share Posted March 9, 2010 lol, you're getting tricky now. put an input in the form with the photo they're viewing (like a hyperlink if it's just stored on the server), so that when they submit the form, the page reloading knows what image they were just viewing. and then use php to place the $_POST['previouspic'] into the img tag where you want the previous pic to display. Quote Link to comment https://forums.phpfreaks.com/topic/194584-need-to-submit-a-value-on-radiobutton-click-php-picture-rating-system/#findComment-1023372 Share on other sites More sharing options...
lupld Posted March 9, 2010 Share Posted March 9, 2010 just out of curiosity, what kind of experience do you have with this sort of thing? you seem like you've been doing work like this before, but you're really stepping it up this time. if the javascript isn't working, submit() might be reserved. The example I found used submitform() instead. and it showed the syntax for onclick like this: onclick="submit()". Just a couple of errors I might have made, I only code for fun, so I do a lot of trial and error to get things right. Quote Link to comment https://forums.phpfreaks.com/topic/194584-need-to-submit-a-value-on-radiobutton-click-php-picture-rating-system/#findComment-1023373 Share on other sites More sharing options...
prallen Posted March 9, 2010 Author Share Posted March 9, 2010 Alright thanks a lot I'm gonna try some of that stuff right now. I've been doing some work with php and mysql... for a few years... just kind of playing around though. Quote Link to comment https://forums.phpfreaks.com/topic/194584-need-to-submit-a-value-on-radiobutton-click-php-picture-rating-system/#findComment-1023379 Share on other sites More sharing options...
lupld Posted March 9, 2010 Share Posted March 9, 2010 same here, I'm usually on aim, if you need some specific help let me know. if you're storing the images in mysql that's the one thing I haven't really dabbled with, so I don't exactly know how it works, but I think you can pick out what I've said so far and make it work. Good luck Quote Link to comment https://forums.phpfreaks.com/topic/194584-need-to-submit-a-value-on-radiobutton-click-php-picture-rating-system/#findComment-1023380 Share on other sites More sharing options...
prallen Posted March 9, 2010 Author Share Posted March 9, 2010 Thanks a lot man, worked like a charm. What i'm actually going to do to show the picture and its rating is include a second variable $picID in the $_POST. Then i'm going to have an if statemtent EX: if ($_POST != '') with a function that will lookup the information on the picture id based on $picID. Thankss Quote Link to comment https://forums.phpfreaks.com/topic/194584-need-to-submit-a-value-on-radiobutton-click-php-picture-rating-system/#findComment-1023391 Share on other sites More sharing options...
lupld Posted March 9, 2010 Share Posted March 9, 2010 No problem, glad I could help. I'm especially glad it worked off the bat for you, usually I make a lot of mistakes before I get it right. And don't be too intimidated by javascript, it really isn't hard once you get used to it. A good javascript editor like adobe dreamweave goes a long way too. If you look around I'm sure there are some free alternatives. Quote Link to comment https://forums.phpfreaks.com/topic/194584-need-to-submit-a-value-on-radiobutton-click-php-picture-rating-system/#findComment-1023395 Share on other sites More sharing options...
prallen Posted March 9, 2010 Author Share Posted March 9, 2010 One more thing if possible... how can my form submit 2 variables within its $_POST array? i put this within my <form> tags but it does not seem to be working <?php print "<input type = \"hidden\" name = \"UniqueID\" value = \"".$UniqueID."\">"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/194584-need-to-submit-a-value-on-radiobutton-click-php-picture-rating-system/#findComment-1023400 Share on other sites More sharing options...
prallen Posted March 9, 2010 Author Share Posted March 9, 2010 EDIT: Nevermind, it works with static text.. I must have done something wrong while retrieving UniqueID. Quote Link to comment https://forums.phpfreaks.com/topic/194584-need-to-submit-a-value-on-radiobutton-click-php-picture-rating-system/#findComment-1023402 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.