I’ve got something I’ve been struggling with for a while.
I’ve got an autocomplete form (similar to Facebook’s system) that simply shows suggestions for a category a user types into it. So if I started typing CodeC, it would offer CodeCanyon as a suggestion which I can click and it populates the text box with it.
When a suggestion is clicked, it also creates a new element like this:
data here
The DATA ID above is the data I need to extract…it’s populated by the autocomplete form and is simply an integer.
I can’t seem to figure out how to get that data into PHP when the form is submitted using POST.
I think using client side jquery to get the data ginseng to the server would make sense.
Try something like this
var dataID = $('.xxxxx').attr('rel');
…and then send that ID to the server using that Ajax request.
I’d be able to help you a bit better if I knew how you are updating your data, and how you intend to sed the form. Could you show us the code you are using to populate the results and send the form.
I’d be able to help you a bit better if I knew how you are updating your data, and how you intend to sed the form. Could you show us the code you are using to populate the results and send the form.
----- The page that does stuff with the data submitted. -----
// Get input data
$title = strip_tags(get_input('title')); // message title
$message_contents = get_input('message'); // the message
$send_to = get_input('send_to'); // this is the user guid to whom the message is going to be sent
$reply = get_input('reply',0); // this is the guid of the message replying to
// Cache to the session to make form sticky
$_SESSION['msg_to'] = $send_to;
$_SESSION['msg_title'] = $title;
$_SESSION['msg_contents'] = $message_contents;
I think the best way to do it would be to add a hidden input field in your form, and then when a form submit request is sent, update the hidden field with the id of the before the form data is actually sent to the server.
ie:
HTML:
------------------------------------------------------
JAVASCRIPT:
$(form id / context).submit(function(){
$('#data_id').val(value of li rel)
});
------------------------------------------------------
PHP:
$data = $_REQUEST['data_id'];