Jump to content

need to submit a value on radiobutton click (PHP picture rating system)


prallen

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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."\">";
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.