3

I have a TinyMCE inline form which posts to qry.php. The content gets sent over to qry.php with a key of "edit_me". I want the default behavior where the content gets sent using the name attribute.

<script type="text/javascript">
    tinymce.init({
        selector: '#edit_me',
        inline: true
    });
</script>
<script type="text/javascript">
    $(document).ready( function(){
        $('#input_form').ajaxForm({url: 'qry.php', type: 'post'});
    });
</script>


<form id="input_form" method="post">

    <fieldset name="input" id="edit_me"></fieldset>

    <input class="hide" name="form" value="index_s2">
    <input type="submit" name="submit" value="Submit">

</form>

Here's my qry.php. I'd like the be able to use "input" instead of the ID.

<?php
require_once('connect.php');

if(isset($_POST['edit_me'])) {

    $form = mysqli_real_escape_string($connect, $_POST['form']);
    $input = mysqli_real_escape_string($connect, $_POST['edit_me']);

    echo $input;

    $update_qry = "UPDATE content SET html='{$input}' WHERE section_ID='{$form}'";

    if(mysqli_query($connect, $update_qry)){
        echo "Records added successfully.";
    }
    else {
        echo "Failed";
    }
}
?>

Note that the code works fine as it is, I just don't want it like that.

Matt
  • 1,518
  • 4
  • 16
  • 30

1 Answers1

0

I found a workaround for my problem which is to access the #edit_me ID (which is variable) using an index number which means I can use multiple ID's.

<?php
require_once('connect.php');

if(isset($_POST['submit'])) {

    $post_array = array_values($_POST); // new solution

    $form = mysqli_real_escape_string($connect, $_POST['form']);
    $input = mysqli_real_escape_string($connect, $post_array[0]); // TinyMCE content is the first item

    $update_qry = "UPDATE content SET html='{$input}' WHERE     section_ID='{$form}'";

    if(mysqli_query($connect, $update_qry)){
        echo "Records added successfully.";
    }
    else {
        echo "Failed";
    }
}
?>

#edit_me was a temporary name which would later be replaced with something like #content_1, #content_2 etc... as there are multiple forms.

Matt
  • 1,518
  • 4
  • 16
  • 30