PHP Help - Get data from <li></li>


#1

Hi Guys…

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.

    In other words, I need this:

    <?php $data = DATA ID; ?>

    Anybody have any ideas?

    Thanks!
    Alex


    #2

    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. :slight_smile:


    #3
    ||+359782|Reaper-Media said-||

    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. :slight_smile:

    Here’s what I’m doing…

    ----- The JS -----

                    var li = $(document.createElement("li"));
                    var input = $(document.createElement("input"));
                    li.attr({
                        "class": "bit-input",
                        "id": elemid + "_annoninput"
                    });
                    input.attr({
                        "type": "text",
                        "class": "maininput",
                        "size": "25"
                    });
                    holder.append(li.append(input));
                    input.focus(function() {
                        complete.fadeIn("fast");
                    });
                    input.blur(function() {
                        complete.fadeOut("fast");
                    });
                    holder.click(function() {
                        input.focus();
                        if (feed.length && input.val().length) {
                            feed.show();
                        } else {
                            feed.hide();
                            browser_msie ? browser_msie_frame.hide() : '';
                            complete.children(".default").show();
                        }
                    });
    

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

    #4

    No idea why that’s showing up without any breaks…sorry.


    #5
    jalexsmith said

    No idea why that’s showing up without any breaks…sorry.

    Wrap your code tags in pre tags :slight_smile:

    Or use something like pastebin or snipplr. There’s another good one around but I can’t think of it off the top of my head…


    #6

    Changed code tags to pre tags :slight_smile:

    @SevenSpark: pastie? :wink:


    #7

    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'];
    
    

    Let me know if that helps :slight_smile: