如何将名称属性用于POST而不是TinyMCE的ID

时间:2017-06-21 17:18:25

标签: php jquery html ajax tinymce

我有一个TinyMCE内联表单,发布到qry.php。内容将通过“edit_me”键发送到qry.php。我想要使​​用name属性发送内容的默认行为。

<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>

这是我的qry.php。我希望能够使用“输入”而不是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";
    }
}
?>

请注意,代码工作正常,我只是不想那样。

1 个答案:

答案 0 :(得分:0)

我找到了解决问题的方法,即使用索引号访问<?php $apiKey = "API_KEY"; $url = "https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=".$apiKey; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL,$url); $result=curl_exec($ch); curl_close($ch); $data = json_decode($result,true); $components = $data["results"][0]["address_components"]; // filter the address_components field for type : $type function filter($components, $type) { return array_filter($components, function($component) use ($type) { return array_filter($component["types"], function($data) use ($type) { return $data == $type; }); }); } $zipcode = array_values(filter($components, "postal_code"))[0]["long_name"]; $citystate = array_values(filter($components, "administrative_area_level_1"))[0]["long_name"]; var_dump($zipcode); var_dump($citystate); ?> ID(可变),这意味着我可以使用多个ID。

#edit_me

<?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#content_1等等,因为有多种形式。