Multiple records of model in a single form - forms

I would like to create a form which works in the connection table between a "M:N" relation.
So the user is able to add multiple rows of a parent model in one form.
Can some help me to bring this working? What should be the associations?
My problem is the same like here.
Thank you very much for your help!

Looks like you are trying to do some nesting have you tried these tuts from railscasts
http://railscasts.com/episodes/196-nested-model-form-part-1
http://railscasts.com/episodes/197-nested-model-form-part-2
Also checkout this for some guidance on the types of relations you want
http://railscasts.com/episodes/47-two-many-to-many

You could always do that manually inside the controller without rails' form_for helper.
Thats actually what the second part of the answer to the question you linked to suggests.
Just like the answer mentions, giving <input> fields names ending with [] (e.g. <input type="text" name="field[]">) results in that field being an array in the params hash inside the controller.

Related

ACF - category field data to its containing posts/pages

I am trying to find a general way to bring the field data of a category to the posts in this category.
My categories have fields like "e-mail", "adress" etc. and I can show this data on the category pages. It would make sense that the posts/pages assigned to a category somehow inherit the field data of their parent category.
Is there a way to achieve this through functions.php or some setting?
Some help would be greatly appreciated. Thanks!
Cheers, Markus
I am pretty sure you would have to do a separate query in the post/page template to get the acf field data associated with the category of the posts/pages.
You could make this into a function. You would send the categories from the template page for your posts or pages to this function and get the template to assemble the acf metadata.

Query subform, not working when used through navigation form

I'll keep this as clear as I can:
My database has two tables:
Clients
Contacts
They have a relationship: For each client (Which is a company, for your understanding) there can be any number of related contacts.
The database has three relevant forms:
SearchFrm
NavigationFrm
ContactsSubFrm
SearchFrm is a form that reads from the Clients table, and has a combo box that, according to chosen record (name), displays all it's other fields in their respective text boxes.
Inside SearchFrm, ContactsSubFrm appears as a datasheet subform, that displays all contacts related to the chosen record in the form, (using a query of Contacts.[Workplace ID])=[Forms]![SearchFrm]![ID]
NavigationFrm serves as a means of navigation between forms. For now, it's only for SearchFrm, but more will come.
And now, the problem: The query that ContactsSubFrm runs doesn't work inside NavigationFrm, when run, I get an input window for [Forms]![SearchFrm]![ID] every time it's suppose to run. This only happens inside navigation.
I'm pretty sure this is because the SearchFrm form itself is closed, and has a problem working through a navigation form, but I can't think of a solution.
Thank you very much.
I was looking for the answer to the same question, so I thought I'd put my solution here in case anyone else comes looking for it...
As stated above, you have to reference the field within your form within your navigation form in your query (as opposed to just the field within your originally created form.)
The best way to do this is:
Open your navigation form.
Open any other form.
Access the expression builder from the other form.
Find the field in your navigation form that you need to reference. Mine looked something like this:
Forms![NavigationForm]![NavigationSubform].Form![Field]
Copy and paste into your query
Since your form moved location (now inside a navigation form), You could try to modify your query from: [Forms]![SearchFrm]![ID] to: [Forms]![NavigationFrm]![SearchFrm]![ID]
I solved this by changing the reference in the query itself to
[forms]![frmNavigationForm]![NavigationSubform].[Form]![ID]

How to make a field "autocomplete"?

I can't figure out how to make a field autocomplete in ATK.
I guess it has something to do with the type "reference" but still not sure.
Suppose I'm looking for a client name in a "line" type field, then the autocomplete should list me all/topXX matching names.
Scenario 1:
Once I hit [Enter] I'd need all that row from DB loaded in a form fields so I can edit the record.
I guess this requires getting the client ID first then posting to an "edit" page then calling "loadData()" method for that ID and populate fields.
Scenario 2:
I'm assignig a job request to a client. First I find the client then I could store its ID in a hidden field to be posted then.
Any advice?
TIA
I would suggest you to go with 2 forms. First form with a single field, and when field is changed it automatically reloads second form including the parameter.
You will also need an autocomplete field. Autocomplete is somewhat buggy in 4.0, but it have been polished up in 4.1 by using a technique in http://jqueryui.com/demos/autocomplete/#combobox
For use with models and controllers and also dropdown, example is here:
http://codepad.agiletoolkit.org/reloadform
Alternative example:
http://demo.atk4.com/demo.html?t=22
Since 4.1, you can also use autocomplete fields instead of reference:
$form1->addField('autocomplete','user');

coldfusion - bind a form to the database

I have a large table which inserts data into the database. The problem is when the user edits the table I have to:
run the query
use lots of lines like value="<cfoutput>getData.firstname#</cfoutput> in the input boxes.
Is there a way to bind the form input boxes to the database via a cfc or cfm file?
Many Thanks,
R
Query objects include the columnList, which is a comma-delimited list of returned columns.
If security and readability aren't an issue, you can always loop over this. However, it basically removes your opportunity to do things like locking certain columns, reduces your ability to do any validation, and means you either just label the form boxes with the column names or you find a way to store labels for each column.
You can then do an insert/update/whatever with them.
I don't recommend this, as it would be nearly impossible to secure, but it might get you where you are going.
If you are using CF 9 you can use the ORM (Object Relation Management) functionality (via CFCs)
as described in this online chapter
https://www.packtpub.com/sites/default/files/0249-chapter-4-ORM-Database-Interaction.pdf
(starting on page 6 of the pdf)
Take a look at <cfgrid>, it will be the easiest if you're editing table and it can fire 1 update per row.
For security against XSS, you should use <input value="#xmlFormat(getData.firstname)#">, minimize # of <cfoutput> tags. XmlFormat() not needed if you use <cfinput>.
If you are looking for an easy way to not have to specify all the column names in the insert query cfinsert will try to map all the form names you submit to the database column names.
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7c78.html
This is indeed a very good question. I have no doubt that the answers given so far are helpful. I was faced with the same problem, only my table does not have that many fields though.
Per the docs EntityNew() the syntax shows that you can include the data when instantiating the object:
artistObj = entityNew("Artists",{FirstName="Tom",LastName="Ron"});
instead of having to instantiate and then add the data field by field. In my case all I had to do is:
artistObj = entityNew( "Artists", FORM );
EntitySave( artistObj );
ORMFlush();
NOTE
It does appear from your question that you may be running insert or update queries. When using ORM you do not need to do that. But I may be mistaken.

Getting the value and text from a selectbox in ColdFusion

I have several values in a select box. Is it possible to get both the value and the text between the <option> tags when the form is submitted?
<option value="413">Highland </option>
<option value="414">Inverclyde </option>
Alternatively I suppose I have to store the names in a table or array for retrieval but would be much easier if I could just insert both in the table when the form is submitted.
As Stephen Moretti pointed out, there are at least two ways to derive the text from the value.
You could also use a list containing the value proper and the text for the value of the select. So, instead of:
<option value="23">Twenty Three</option>
use
<option value="23,TwentyThree">Twenty Three</option>
and use list*() functions on the back end.
Finally, you could use JavaScript to store the text of the selected option in a hidden field (or similar). This, in my opinion, is the least attractive option. First, it would be more work than the other options, and second because it will fail if JS is turned off on the client.
Depending on the size/type of data, I would probably either rewrite the option values, as I've described, or switch off a lookup table, as Stephen described.
If you've only got a few value/text pairs in your select, then just store the value. If you need to output the text somewhere else other than the select, just write a if/elseif/else or case block to display the text.
If you've got quite a few value/text pairs then it would be best to create a lookup table in your database with these in. You can use this to generate your select and output the text from a stored value at a later date.
How do you tell if you've got too many value/text pairs? If writing the case block to display them results in a silly amount of tedious code. ;)
Another option would be to store a struct of your value/text pairs in the session scope, then on your form action page you can use the value to easily look up your text.
The beauty of this is that it's entirely server-side and does not include an extra trip to the database.
Delete the struct from the session scope if you don't want to keep it around.