Search code examples
phpwordpresstextareahtml-entitiesmarquee

Show multiple input textbox if checkbox are checked simultaneously as marquee


I am not experienced with this but I think I am on good way. I need help from someone experienced. Think it is interesting issue Let's say there is 3 checkboxes and 3 textboxes.

<input type="checkbox" name="check[1]" value="1.">  
<textarea name="text[1]" ></textarea>

 <input type="checkbox" name="check[2]" value="2.">   
 <textarea name="text[2]" ></textarea>

 <input type="checkbox" name="check[3]" value="3.">  
 <textarea name="text[3]" ></textarea>

And I need to create a loop which will check foreach check[%] if is checked with if (isset($_POST['check[%]'])) to add all checked text[%] textboxes values to some $value

$value needs to be output as one line in as marquee

I think it needs to be $value needs to go trough html_entity_decode but I am not sure. finally output to be something like

$output .= "<font><marquee scrollamount='3' BEHAVIOR=SCROLL DIRECTION="left"> $value"."</marquee>"."</font>";

Solution

  • For starters, for a PHP POST I would not use brackets in the name of the input values.

    index.php:

    <form action="test.php" method="POST">
        <input type="checkbox" name="check1" value="1.">  
        <textarea name="text1" ></textarea>
        <input type="checkbox" name="check2" value="2.">   
        <textarea name="text2" ></textarea>
        <input type="checkbox" name="check3" value="3.">  
        <textarea name="text3" ></textarea>
        <button type="submit">Submit</button>
    </form>
    

    test.php:

        $total_checkbox_num = 3;
        $final_message = '';
        if ($_SERVER["REQUEST_METHOD"] == "POST") {
            foreach($_POST as $key => $value) {
                if (!is_array($key)) {
                    $_POST[$key] = htmlspecialchars(stripslashes(trim($value)));
                }
            }
            for($i = 1; $i <= $total_checkbox_num; $i++) {
                if(isset($_POST['check'.$i])) {
                    $final_message .= $_POST['text'.$i];
                }
            }
            $output = '<font><marquee scrollamount="3" behavior="scroll" direction="left">' . $final_message . '</marquee></font>';
            echo $output;
        } else echo "There was an error";