Cognis Cognis - 1 year ago 367
jQuery Question

Use X-editable for Bootstrap to send values to post.php

I use Twitter Bootstrap and decided to use X-editable with it. I put in all the necessary files and it works fine except that I want to pass values to

where I want PHP to process

Markup of the editable element is

<a href="#" id="example">Example</a>

I call it like this

$(function() {
$.fn.editable.defaults.mode = 'inline';

type: 'text',
pk: 1,
url: 'post.php',
title: 'Enter example'

I used jEditable as an inline editor in which I passed on values to a php file with no problems and I would like to do so with X-editable but I can't seem to do it.

How do I pass the values to
so I can use php to manipulate the data?

Answer Source

<a href="#" id="example">Example</a>

you must add data-name=""

<a href="#" id="example" data-name="db-col-name">Example</a>

so when you access it in post.php, you can do like this:

$name = $_POST['name'] // $_POST['name'] catches the data-name value

$pk= $_POST['pk'] // the pk(primary key) that you assigned

$value= $_POST['value'] // the new value after you use the inline edit

after that you could do something like this

if(!empty($value)) {

$result = mysql_query('update users set '.mysql_escape_string($name).'="'.mysql_escape_string($value).'" where user_id = "'.mysql_escape_string($pk).'"');

} else {
    header('HTTP 400 Bad Request', true, 400);
    echo "This field is required!";
} `

credits to the makers of x-editable its from their php sample more info here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download