A
A
Artem2020-05-17 10:55:13
PHP
Artem, 2020-05-17 10:55:13

How to hide a specific form after a specific user click?

There are goods the goods have a rating. The user can vote but the rating remains visible. After voting, the rating should be blocked so that the user (cookie) no longer votes. Thank you in advance for your attention!

$ra1 = $row['rating']; 
    $checked = intval($ra1); 
    $count = 5; 
    $inputs = '';
    for($i = 1; $i <= $count; $i++) { 
    $checked_attr = $i == $checked ? ' checked' : '';
    $inputs .= '<input  class="rating-input" id="mod' . $i . '' . $row["products_id"] . '" star-attr="' . $row["products_id"] . '" name="radio-rating" type="radio" value="' . $i . '"' . $checked_attr . '>';
    $inputs .= '<label class="rating-star" for="mod' . $i . '' . $row["products_id"] . '" ></label>';
    };

    // вывод
    echo '
    <div  class="order_right">  
     <div  class="wrap_stars">
      <form class="form-rating" method="POST">
      <fieldset class="fieldset">
      <legend></legend>
      <div class="rating-group">

       ' .$inputs . '
      
       </div>
      </fieldset>
        <div class="count_block">
        <!-- Статистика -->
        <ul class="count" >' . $row["rating"] . '</ul>
        </div>
       </form>
      </div>
    </div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
NKwork, 2020-05-17
@shylov

(If I understood the question correctly, there is not enough additional information.) I will
try to answer in detail.
1. Using cookies for this purpose is not entirely reliable (the user can simply clear cookies, log in incognito, etc.) And vote in this way again. Therefore, it would be better to store information about a particular vote in the database as well. Cookies are not suitable for this purpose (in this task, you will need them to identify the user in the system).
2. You can hide the form, for example, using JS. (For example) At the time of passing parameters to the page (on the backend), check whether a particular user voted for this particular product, pass the appropriate parameter. Depending on the value of this parameter, you do on the front of the check and display what you need (hide what you need). (You can also do this with PHP)
3. It is also highly desirable to make the appropriate checks in the method responsible for receiving the form, since this way the user, despite the fact that the voting form is not visible, can still send a request with the appropriate data for recording , and if you do not have a check, then the information about the voice will be recorded again. (one visual hiding or "non-drawing" of the form cannot do the job)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question