Save radio button checked status to change color of object if checked

Question

I am using the wp_insert_post function to submit form information from users to show a five star review and description. The form takes a name and description which I can save as title and content but in order to show the correct highlighted stars I need to save the checked status of the stars and store them in a custom field so I can use them to assign the color from css (at least thats the way I am understanding it). Not sure how to grab that information. Here is some code:

    if(isset($_POST['new_post']) == '1') {
$post_title = wp_strip_all_tags($_POST['postTitle']);
$post_category = $_POST['review'];
$post_content = wp_strip_all_tags($_POST['postContent']);
$value = $_POST['rate'];

$category='review'; // category name for the post
$cat_ID = get_cat_ID( $category ); // need the id of 'review' category
//If it doesn't exist create new 'review' category
if($cat_ID == 0) {
$cat_name = array('review' => $category);
wp_insert_category($cat_name); // add new category
}
//Get ID of category again incase a new one has been created
$new_cat_ID = get_cat_ID($category);

$new_post = array(
      'ID' => '',
      'post_author' => $user->ID, 
      'tax_input' => array($category->taxonomy => array($category->review)),
      'post_category' => array($new_cat_ID),
      'post_content' => $post_content, 
      'post_title' => $post_title,
      'post_value' => $value,
      'post_type' => 'review',
      'post_status' => 'pending'
    );

$post_id = wp_insert_post($new_post);


// This will redirect you to the newly created post
//$post = get_post($post_id);
wp_redirect($post->guid);

}

Here is how my radio buttons look for the user to highlight the stars

     <input type="radio" name="rate" id="rate-1">
     <label for="rate-1" id="rate-1-label" class="fas fa-star"></label>

And then after it saves I was going to use these radio button and labels to show the highlighted stars according to the checked value that the user has selected:

      <input type="radio" name="rate-output" id="rate-1-output" >
      <label for="rate-1-output" id="rate-1-output-label" class="fas fa-star" ></label>

Which is the same thing but with different id and name and without a hover attribute like the ones for the user to select. I hope this makes sense. If not feel free to ask me some more questions. if anyone can help with this it would be greatly appreciated. Hope all is well. Thanks again in advance

0
Jah Rik 2 months 0 Answers 11 views 0

Leave an answer