Cognis
Cognis

Reputation: 65

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 post.php where I want PHP to process $_POST["value"].

Markup of the editable element is

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

I call it like this

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

  $('#example').editable({
  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 post.php so I can use php to manipulate the data?

Upvotes: 0

Views: 13213

Answers (2)

Sudhanshu sharma
Sudhanshu sharma

Reputation: 1967

you should do something like this

<a href="#" id="roll_no" data-type="text" data-pk="<?php echo $row['id'] ?>" data-url="ajax.php" ><?php echo $row['roll_no']; ?></a>

Reference :- jQuery x editable tutorial

Upvotes: 1

reid
reid

Reputation: 110

<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

Upvotes: 3

Related Questions