Form Action=Post

Form Action=Post

XstreamINsanityXstreamINsanity Posts: 23Questions: 0Answers: 0
edited August 2010 in General
My issue is that I have records and controls being created on the fly which mean the names and IDs are as well. I'm doing server-side processing and right now only returning 10 records at a time. If I define a form tag on the table, it only returns to me the first records information (I can't search by element as the ids are dynamic). I want to put a form tag on each row, but after looking at the javascript, I don't think it's possible. I say that because it take the JSON data and makes an element (TD) for each value in the record. If I put the opening form tag in one element and the closing in another, that violates HTML rules (the parent element may not be ended before thei child's element). Is there a way to add a "form action=Post" to each row already that I'm just not aware of, or will I have to modify the javascript some? Thanks for any help.

Replies

  • XstreamINsanityXstreamINsanity Posts: 23Questions: 0Answers: 0
    Allan,

    Looking at the js file, it looks like in the _fnGatherData(oSettings) function is where you loop through the elements and put them to the TD elements. Where in there would I be able to say (psuedocode since I'm not too familiar with javascript) "if the td value contains '
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    As you say, wrapping TR elements individually in FORM tags will invalidate the HTML - so not an easy solution to this one (that I'm aware of!) - sorry.

    Allan
  • XstreamINsanityXstreamINsanity Posts: 23Questions: 0Answers: 0
    Well, I don't want to wrap the TR elements, I want to wrap all of the TD elements in the TR element in a Form tag. I know that this can be done. And I was wrong on the function. I found the _fnAddCells where it "document.createElement('td');, but I need to somehow say (if you can write this for me, that'd be great, but you don't have to):

    if (aData /*Contains or however you do that*/ "
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I don't believe that would be valid either I'm afraid. Looking at the HTML doctype - a TR element con only have a TH or TD element as a child:

    [code]
    <!ELEMENT tr (th|td)+>
    [/code]
    Allan
  • XstreamINsanityXstreamINsanity Posts: 23Questions: 0Answers: 0
    edited August 2010
    I believe you said you weren't that familiar with MVC before, but I'll give you a quick example of something I've seen/we've done. MVC (Model/View/Controller) we build the HTML markup in the View and put the code we want to execute in the controller. Well, we've before, in the View used "using Html.BeginForm()" in the middle of a TR element and closed it before the closing of the TR element. The BeginForm is just a helper tag (replaces itself with the right markup). When I've done this and run the site and looked at the sorce, it's created a form tag within the TR, but never inside of a TD. That's the reason I believe it can be done. However, if you are meaning that the appendChild fuction won't append a form tag, then oh, that sucks. I'm trying to find different things online that will allow me to try it myself, but if you think of anything, please let me know. Thanks.

    P.S. Also, if I put an alert("Hello"), as long as the code gets to that point, I should see a window pop up, right? I ask because I'm trying that now and getting nothing. Thanks.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    What I was getting at is that this:

    [code]


    ...
    ...
    ...


    [/code]
    which is what it sounds like you are looking for, is not valid HTML. The form tag could probably go into the TD elements, but again, that doesn't sound like what you want. Since you are using Javascript though, one option would be to read the values from the row where the submit button was pressed, put them into a form dynamically and then submit that.

    Allan
  • XstreamINsanityXstreamINsanity Posts: 23Questions: 0Answers: 0
    edited August 2010
    Well, I'm trying to do it another way now because I was getting too confused with the javascript (the deadline kept entering my mind). But that is valid HTML. Probably not conventional, but it is allowed. It allows the user to, maybe in only MVC, not sure, specify different forms so when you return to the controller code, the only form information you have is that of the selected button. Essentially, you could have...

    [code]



    ...
    ...
    ...
    ...
    ...
    ...





    ...
    ...
    ...
    ...
    ...


    ...
    ...
    ...
    ...
    ...


    ...
    ...
    ...
    ...
    ...


    ...
    ...
    ...
    ...
    ...




    [/code]

    I'm not sure if it would work in normal code and if it does how, but I know in MVC2 when you say FormCollection, it gets the form items from the form that did the post back and nothing else. I don't know, I got all of this from stuff my coworkers were doing and looking at their HTML source after rendering the page, but since I'm in charge of working on the dataTables, they wanted me to find out how to use Server-Side processing and still be able to use the form. Since in the view I'm not iterating through objects, I can't put a form tag and dynamically change it's name. Right now, I have four controls per row; 3 drop down and 1 button. The only control that does a post is the button. It is to get the values from the three drop downs and use them to determine what SQL Update statement to run. If we wrote the view with client-side processing on the dataTable, then we'd have the form tag around the controls (not including the other 8 columns, they can be out of the form tag) and dynamically set the tag name. That is what worked. When we had issues with too much data and needed to use server-side processing, we lost that functionality. Now, if I update the first record in the table, it all works fine (well, the way I had it yesterday morning, much has changed since then). But they need to be able to update any record in the table. And we're trying to do it where each row has it's own controls, not any master controls. I do appreciate your help and hope all is well.
This discussion has been closed.