How can I manipulate a form / inputs to be ignored when a form is submitted
Asked Answered
A

3

7

I'm using ExpressionEngine and SafeCracker along with Ajax (plugin: jquery.form.js - http://jquery.malsup.com/form/).

Best I can tell, SafeCracker will only allow for updating a single entry at a time. However, the UI / UX necessitates that a list be displayed. I've proof of concept'ed an entry by entry on-demand form. That is, click a particular edit link next to each entry and a snippet of jquery creates a form along with displaying a submit button. Click submit and that single entry updates. The inputs don't exist until the Update link is clicked

What I would prefer to do, if possible, is to create the non-form and form versions of each entry as the page is renbered and use some sort of toggle to display one or the other. Again, doable. Then, when I click the Edit link I'd add the necessary attributes to the input so that entry's form elements will be read but the other (display: none) elements for the other entries will be ignored. I'm thinking (out loud) that if I add the attr("name", some-value) that would work. That is, an input with no name will be ignored.

Yes, I can test this and I will. However, even if it works I'm not sure if it's a best practice and/or there's a more ideal way of accomplishing my ends. I'm here looking for validation and/or additional expertise and input.

Thanks in advance.

Armament answered 27/5, 2012 at 15:52 Comment(0)
W
13

Just set disabled property to inputs and they will excluded from Form submission, whatever input fields are hidden or visible. Different jQuery methods, like submit() and serialize() follow specification of HTML 4 and exclude all disabled controls of a forms. So one way is to set

$('your_input').prop('disabled', true);

or ,

$('your_input').attr('disabled', 'disabled');

Check following link:

http://www.w3.org/TR/html401/interact/forms.html#successful-controls

Also, you may use a general button instead of a submit, as result you can handle click event on it and within that event you can make exclusion, validation, manipulation on values and what ever you like.

Weatherbeaten answered 27/5, 2012 at 16:5 Comment(1)
Thanks for the extra details on the linky. Big big help.Armament
C
3

You can put a disabled attribute on them server side or set the property via jQuery:

$(".hidden input").prop("disabled", true);
Cabinda answered 27/5, 2012 at 16:2 Comment(0)
C
0

If you don't want to disable the input, you may set form attribute to empty string

<input name="myfield" form="" />

Calve answered 11/8 at 20:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.