0

I'm currently having a problem with a <textarea> not posting with the rest of the form. Currently the <textarea> will only post data supplied from $r['bio'] that's used to fill in the <textarea> if there's already content in $r['bio'].

Things I've tried with no success

  1. moving the submit button to the bottom of the page.

  2. giving the form an unique id with $FID and adding form='$FID' to the text area

  3. removing var editor = textboxio.replaceAll('textarea'); will let the textarea post as intended but then I lose the WYSIWYG editor.

            $query = $conn->query('SELECT * FROM users');
                while($r = $query->fetch()){
                $memID =  $r['id'];
                $bioID = 'b'.$r['id'];
                $FID = 'f'.$r['id'];
                $ebioID = 'eb'.$r['id'];
                $tbioID = 'tb'.$r['id'];
                $tabioID = 'tba'.$r['id'];
    
                if($r['active'] == 1){
                    $activeStatus = 'Yes';
                }else{
                    $activeStatus = 'No';
                }
    
                if($r['admin'] == 1){
                    $adminStatus = 'Yes';
                }else{
                    $adminStatus = 'No';
                }
    ?>
    
    <div class="userMgmWrap">
    <form method="post" enctype="multipart/form-data">
    <table>
        <tbody>
            <tr>
            <td>Edit Profile Image</td>
            <td><input type="file" name="selectedFile" id="selectedFile"></td>
            <td><input type="submit" value="Upload" name="upload"></td>
            </tr>
        </tbody>
    </table>
    </form>
        <div class="userMgmProfilepic"><img src="images/profilepics/<?php if(isset($r['profilepicture'])){echo $r['profilepicture'];}else{echo 'NULL';}?>" style="width:100%;height:100%;"> </div>
        <div class="userMgmInfo">
            <form method="post">
                <table>
                    <tbody>
                        <tr>
            <!-- Username --><td>Username: </td>
            <!-- Username --><td><?php if(isset($r['username'])){echo $r['username'];}else{echo 'NULL';}?> </td>
            <!-- Username --><td class="<?php echo $tbioID; ?>" style="visibility:hidden"></td>
                        </tr>
                        <tr>
            <!-- Email --><td>Email: </td>
            <!-- Email --><td><?php if(isset($r['email'])){echo $r['email'];}else{echo 'NULL';}?> </td>
            <!-- Email --><td class="<?php echo $tbioID; ?>" style="visibility:hidden"><input type="text" name="newEmail"></td>
                        </tr>
                        <tr>
            <!-- Active --> <td>Active: </td>
            <!-- Active --> <td><?php if(isset($activeStatus)){echo $activeStatus;}else{echo 'NULL';}?> </td>
            <!-- Active --> <td class="<?php echo $tbioID; ?>" style="visibility:hidden">
                                <select name="newActive">
                                    <option selected="selected"></option>
                                    <option value="1">Yes</option>
                                    <option value="0">No</option>
    
                                </select>
                            </td>
                        </tr>
                        <tr>
            <!-- Admin --><td>Admin: </td>  
            <!-- Admin -->  <td><?php if(isset($adminStatus)){echo $adminStatus;}else{echo 'NULL';}?> </td>
            <!-- Admin -->  <td class="<?php echo $tbioID; ?>" style="visibility:hidden">
                                <select name="newAdmin">
                                    <option selected="selected"></option>
                                    <option value="1">Yes</option>
                                    <option value="0">No</option>
                                </select>
                            </td>           
                        </tr>
                        <tr>
            <!-- DOB -->    <td>Birth Date: </td>
            <!-- DOB -->    <td><?php if(isset($r['dob'])){echo $r['dob'];}else{echo 'NULL';}?> </td>
            <!-- DOB -->    <td class="<?php echo $tbioID; ?>" style="visibility:hidden"><input type="date" name="newDOB" id="newDOB"></td>
                        </tr>
                        <tr>
            <!-- Bio -->    <td>Bio: </td>
            <!-- Bio -->    <td><input id="<?php echo $bioID; ?>" type="button" name="viewBio" value="View Bio" onclick="mod(this.id)"></td>
            <!-- Bio -->    <td><input id="<?php echo $ebioID; ?>" type="button" name="modBio" value="Modify Bio" onclick="mod(this.id)"></td>
                        </tr>
                    </tbody>
                </table>
        </div>
        <div class="userMgmInfo2">
            <table>
                <tbody>
                    <tr>
        <!-- First Name --><td>First Name: </td>
        <!-- First Name --><td><?php if(isset($r['firstname'])){echo $r['firstname'];}else{echo 'NULL';}?> </td>
        <!-- First Name --><td class="<?php echo $tbioID; ?>" style="visibility:hidden"><input type="text" name="newFirstName"></td>
                    </tr>
                    <tr>
        <!-- Last Name --><td>Last Name: </td>
        <!-- Last Name --><td><?php if(isset($r['lastname'])){echo $r['lastname'];}else{echo 'NULL';}?> </td>
        <!-- Last Name --><td class="<?php echo $tbioID; ?>" style="visibility:hidden"><input type="text" name="NewLastName"></td>
    
                    </tr>
                    <tr>
        <!-- Social 1 --><td>Social 1: </td>
        <!-- Social 1 --><td><?php if(isset($r['social1'])){echo $r['social1'];}else{echo 'NULL';}?> </td>
        <!-- Social 1 --><td class="<?php echo $tbioID; ?>" style="visibility:hidden"><input type="text" name="NewSocial1"></td>
                    </tr>
                    <tr>
        <!-- Social 2 --><td>Social 2: </td>
        <!-- Social 2 --><td><?php if(isset($r['social2'])){echo $r['social2'];}else{echo 'NULL';}?> </td>
        <!-- Social 2 --><td class="<?php echo $tbioID; ?>" style="visibility:hidden"><input type="text" name="NewSocial2"></td>
                    </tr>
                    <tr>
        <!-- Social 3 --><td>Social 2: </td>
        <!-- Social 3 --><td><?php if(isset($r['social3'])){echo $r['social3'];}else{echo 'NULL';}?> </td>
        <!-- Social 3 --><td class="<?php echo $tbioID; ?>" style="visibility:hidden"><input type="text" name="NewSocial3"></td>
                    </tr>
                    <tr>
        <!-- Edit -->   <td>Edit Account: </td>
        <!-- modify --> <td><input id="<?php echo $tbioID; ?>" type="button" name="modify" value="Modify" onclick="mod2(this.id)"></td>
        <!-- save -->   <td><input id="" type="submit" name="<?php echo $tabioID ?>" value="Save"></td>
                    </tr>
                </tbody>
            </table>
        </div>
    
        <div style="clear: both;"></div>
        <div class="userMgmBio">
            <div class="<?php echo $ebioID; ?>" style="display :none;">
                <textarea id="test"name="newbody"><?php //if(isset($r['bio'])){echo $r['bio'];} ?></textarea>
            </div>
            </form>
            <div class="<?php echo $bioID; ?>" style="display :none;"><?php if(isset($r['bio'])){echo $r['bio'];} ?></div>
        </div>
    </div>
    
    <?php
    
                    if(isset($_POST[$tabioID])){
                        print_r($_POST);
                        //error check up here
                        if($_POST['newEmail'] !==""){
                            if(!filter_var($_POST['newEmail'], FILTER_VALIDATE_EMAIL)){
                                $error[] = 'Please enter a valid email address.';
                                $eerror = 'Please enter a valid email address.';
                            } else {
                                $stmt = $conn->prepare('SELECT email FROM users WHERE email = :email');
                                $stmt->execute(array(':email' => $_POST['newEmail']));
                                $row = $stmt->fetch(PDO::FETCH_ASSOC);
    
                                if(!empty($row['newEmail'])){
                                    $error[] = 'Email provided is already in use.';
                                    $eerror2 = 'Email provided is already in use.';
                                }
    
                            }
                        }//EO email Check
    
                        if(isset($error)){print_r ($error);}
                        if(!isset($error)){
                        //prepare query
                        //newEmail --
                        //newActive --
                        //newAdmin --
                        //newDOB --
                        //newbody --
                        //newFirstName ---
                        //NewLastName --
                        //NewSocial1
                        //NewSocial2
                        //NewSocial3
                            $q = array();
                            if(trim($_POST["newEmail"]) !== ""){
                                $q[] = "email = :newEmail";
                            }
                            if(trim($_POST["newActive"]) !== ""){
                                $q[] = "active = :newActive";
                            }
                            if(trim($_POST["newAdmin"]) !== ""){
                                $q[] = "admin = :newAdmin";
                            }
                            if(trim($_POST["newDOB"]) !== ""){
                                $q[] = "DOB = :newDOB";
                            }
                            if(trim($_POST["newbody"]) !== ""){
                                $q[] = "bio = :newbody";
                            }
                            if(trim($_POST["newFirstName"]) !== ""){
                                $q[] = "firstname = :newFirstName";
                            }
                            if(trim($_POST["NewLastName"]) !== ""){
                                $q[] = "lastname = :NewLastName";
                            }
                            if(trim($_POST["NewSocial1"]) !== ""){
                                $q[] = "social1 = :NewSocial1";
                            }
                            if(trim($_POST["NewSocial2"]) !== ""){
                                $q[] = "social2 = :NewSocial2";
                            }
                            if(trim($_POST["NewSocial3"]) !== ""){
                                $q[] = "social3 = :NewSocial3";
                            }                       
                            if(sizeof($q) > 0){//check if we have any updates otherwise don't execute
                                $query2 = "UPDATE users SET " . implode(", ", $q) . " WHERE id= :id";
                                $stmt = $conn->prepare($query2);
                                $stmt->bindParam(":id", $memID);
    
                                if(trim($_POST["newEmail"]) !== ""){
                                    $stmt->bindParam(":newEmail", $_POST["newEmail"]);
                                }
                                if(trim($_POST["newActive"]) !== ""){
                                    $stmt->bindParam(":newActive", $_POST["newActive"]);
                                } 
                                if(trim($_POST["newAdmin"]) !== ""){
                                    $stmt->bindParam(":newAdmin", $_POST["newAdmin"]);
                                } 
                                if(trim($_POST["newDOB"]) !== ""){
                                    $stmt->bindParam(":newDOB", $_POST["newDOB"]);
                                } 
                                if(trim($_POST["newbody"]) !== ""){
                                    $stmt->bindParam(":newbody", $_POST["newbody"]);
                                }                           
                                if(trim($_POST["newFirstName"]) !== ""){
                                    $stmt->bindParam(":newFirstName", $_POST["newFirstName"]);
                                }   
                                if(trim($_POST["NewLastName"]) !== ""){
                                    $stmt->bindParam(":NewLastName", $_POST["NewLastName"]);
                                }       
                                if(trim($_POST["NewSocial1"]) !== ""){
                                    $stmt->bindParam(":NewSocial1", $_POST["NewSocial1"]);
                                }
                                if(trim($_POST["NewSocial2"]) !== ""){
                                    $stmt->bindParam(":NewSocial2", $_POST["NewSocial2"]);
                                }           
                                if(trim($_POST["NewSocial3"]) !== ""){
                                    $stmt->bindParam(":NewSocial3", $_POST["NewSocial3"]);
                                }                               
                                $stmt->execute();
                            }
                            //echo "<meta http-equiv='refresh' content='0'>";
    
    
    
                        }
    
                    }
    
                }// EO while Loop
    ?>
    
    <script type="text/javascript">
    // Create a Textbox.io Editor for the matched element(s)
        var editor = textboxio.replaceAll('textarea');
      //var editor = textboxio.replace(#class or ID);
    function mod(value){
    
        var elements = document.getElementsByClassName(value);
        for (var i = 0; i < elements.length; i++) {
            if(elements[i].style.display  == "none"){
                elements[i].style.display  = "block";
            }else{
                elements[i].style.display  = "none";
            }
    
    
        }
    
    }
    function mod2(value){
        var elements = document.getElementsByClassName(value);
        for (var i = 0; i < elements.length; i++) {
            if(elements[i].style.visibility  == "hidden"){
                elements[i].style.visibility  = "visible";
            }else{
                elements[i].style.visibility  = "hidden";
            }
    
    
        }
    
    }
    </script>
    </div>
    
Mr Lister
  • 45,515
  • 15
  • 108
  • 150
timmie124
  • 13
  • 2
  • Does it work if you try a simple page that doesn't load content from the database? This looks like it might be too complex to track down in a stack overflow answer, perhaps log a case at https://support.ephox.com/ ? – Spyder Aug 27 '18 at 04:43
  • So I ended up trying a temporary work around by having the edit bio button go to a different page and just have the text area in its own place by itself, But I encountered the same issue. From what I can figure out textbox.io only posts the textarea if the button being used is named "submit" ie I couldn't find this stated anywhere in the docs but going to keep playing around and see if there's a way to make it post when a button isn't named submit. – timmie124 Aug 28 '18 at 17:07
  • Ah, yes, I think that was related to our ability to intercept the submit process. Under the hood it cancels the original submit, waits for images to upload, and then triggers submit again. This only works in specific scenarios, so for anything advanced manual content retrieval (which is asynchronous if you support image upload) is the better solution. – Spyder Sep 06 '18 at 07:17

0 Answers0