0

I'm working on a rating system. The user can rate an item with the dropdown menu:

<select name = "theRating">
<option>Select...</option>
<option>1 Star</option>
<option>2 Stars</option>
<option>3 Stars</option>
<option>4 Stars</option>
<option>5 Stars</option>
</select>

In the same document, just a few lines later, I want to send the selected option in a url via

<form action="', $scripturl, '?action=rateThisThing?rating=',$_POST['theRating'],'" method="post">
<input type="submit" value="Rate this"></form>

Why doesn't this work? $_POST['theRating'] seems to be empty [or at the very least, it's not showing up in the URL upon redirection...]

1
  • if you want to send menu value in the URL you might want to use method="get" so after submit it goes like page.php?theRating=1, from there you use $_GET but not sure how you want to handle the value afterwards. Commented Sep 21, 2012 at 1:51

2 Answers 2

1

LOTS of issues here. First the nitpicky then the major problems. The nitpicky: You're using the wrong concatinator for PHP: it's ., not , and you need to include it inside PHP tags (<?php ?>)

However, that's irrelevant, because you're fundamentally misunderstanding the role of PHP vs javascript. PHP is a server-side language and can only be accessed before content is served to the client (ajax aside). You're also not formatting the url string of your form correctly. If you're passing multiple variables in a URL you seperate them with an ampersand (&), not a ?.

Also, if you're trying to send the information via post as you specify in your form, then why try to pass the data in the url? Just include the select inside the form and set your form's method to get:

<form action="target_file.php" method="get">
 <select name="theRating">
  <option>Select...</option>
  <option>1 Star</option>
  <option>2 Stars</option>
  <option>3 Stars</option>
  <option>4 Stars</option>
  <option>5 Stars</option>
 </select>
<input type='hidden' name='action' value='rateThisThing' />
 <input type="submit" value="Submit" />
</form>
Sign up to request clarification or add additional context in comments.

Comments

0

In order to have data available via $_POST, something must be posted:

<form action="" method="post">
 <select name="theRating">
  <option>Select...</option>
  <option>1 Star</option>
  <option>2 Stars</option>
  <option>3 Stars</option>
  <option>4 Stars</option>
  <option>5 Stars</option>
 </select>
 <input type="submit" value="Submit" />
</form>

Once you submit this form, $_POST['theRating'] will be available on that page. Whatever script is running at $scripturl should either be on this page or included, so the script can use this data.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.