data that non changing frequently in drupal - how to do it right? - php

i got a form (using form api and drupal_Get form ) and i got a form with 50 fields and some of them are non frequently chaning data like hobbies, year of birth , city/country etc...
i currently do just them in array in file and put them in #options=>$array ... is that the fastest way to save resources? or should i use taxonomy/variable_set/database query/block/node or whatever?

variable_get/variable_Set : Is generally used to store admin preferences for the site. If these are user specific I don't think it's a good idea to save them using variable_set
taxonomy : Can also be used for populating the values of
drop-downs, that is for options in the listing. In your case create a vocabulary
called hobbies and add
swimming,reading,drupaling as terms.
Then use the content-taxonomy
to use taxonomy terms as drop downs using CCK moudule.
nodes : Anything that is user
specific should go in as nodes. And
any content that can be created by
the users should also go in as nodes.

For administering forms you can use variable_set/variable_get.
But for your task it seems like that users enter their bio, so in this case you should store each form submission to new "row", as you do now for file (wonder why you don't use DB storing).

Related

Move form entries between Wordpress Gravity Forms

I have a tournament with multiple divisions and multiple forms for which I use gravity forms.
There are times when someone requests to be changed to a different division. However, I am unable to move the competitor from one division to another in gravity forms, as the divisions are each using a different form ID (and they have still not developed a method for helping with this).
How would I go about moving a SINGLE ENTRY from one gravity form to another forms entry list please.
We have many teams at the tournament, so mass export and import is not what i am looking to achieve. Its about being able to move a single entry from one list of entries in one form to another forms list of entries?
ANY help would be greatly appreciated. Even a simple "use this method" in general terms will help me greatly. Would I use some form of JQuery fiddle, a php script, an sql script or what please as Import Entries is not available currently in GF
Regards
You can not do that, but instead maybe you shold design your form to include all types of submissions logic. I mean you can put a drop-down field at the beginning of your form. Then you can use https://gravityview.co/ to edit your single entry field.
I have a workaround for this which i am using in one of my current projects for http://projects.dzign-r.com.au and that is,
1) export both of the the forms (i.e the one from which you need the field to move and the other to which you need this field to be moved to) and it exports these as json files
2) search for the field ID that you need to be moved to another form, cut its json code from the json file and paste it in the other form's json file where you need it to be moved to
3) then import the form back. and test it to make sure it works as you want it, (as a caution you may change the field ID after you paste it in new form to be something which is not used in this form already).
4) once u see everything is fine u may just delete the old form?

Repeating form fields on a form

I am new to Laravel and trying to get my head around how to allow a user to repeat a field.
I have a form that allows a user to create a basic page which has a title and description, I'd like to allow the user to then if they choose create another title and description field using a "Add more" button.
They allow them to re-order these field collections.
Cheers,
Chris
This seems to be less about Laravel and more about general DB Schema, PHP and UI practices. So due to the broad spectrum of answers this requires, I will answer mostly using best practice concepts to avoid being overly wordy (using Laravel for context).
Front-end
For the ability to add another set of fields on the fly, you will want to use a form array:
<div class="field-set">
{{ Form::text('fields[0]["title"]', Input::old('fields[0]["title"]')) }}
{{ Form::textarea('fields[0]["description"]', Input::old('fields[0]["description"]')) }}
</div>
+ Add more
Your 'add-more-link' should have a javascript trigger that will duplicate and append the 'field-set' element with an iteration of the index in the form array
(e.g. fields[1]["title"], fields[2]["title"])
Note: You can do this without JS, but you will have to repost the page with some parameter that increments the amount of fields to create and then loop through that many times while rendering the field sets on DOM generation.
To allow for reordering, I recommend jQuery UI's Sortable. Note: You can accomplish this without JS too by POSTing up or down increments for each field set, but more processing would need to occur in the back-end.
Back-end
In the model where you handle the save, grabbing the data via Input::get('fields') will store it into a PHP array that you can iterate through to validate, parse and store the data.
As for your DB schema, you will need to account for the creation of any number of new fields. This means that will likely need a separate table that will be joined on users.
(Columns: id, user_id, title, description)
In Laravel you can define a Has Many Relationship on the users model that will grab all the titles and descriptions for any given user.
http://laravel.com/docs/eloquent#relationships
I'm not sure you are using forms correctly, although its a little hard to tell from you question.
If you want to create a new resource (with a title and description) you dont add new form fields. You can have an 'add more' button, but this button just spawns another instance of your form which can then be posted.
But to be honest, you question is so vaugue its hard to tell what your problem is...

PHP save dynamic fields to MYSQL database

I have a form with fixed elements like radio button, text boxes, drop downs, etc.
There is also an area of dynamically generated dates and text boxes passes to the Post as an array to be saved into a MYSQL database.
The form is quite big and I would like to give the user the possibility to save it avoiding to have to retype data all the time.
I would also like to give the user the possibility to save their choices by storing a date and a description of their selection.
The problem is that I don't know how to tackle this problem as I don't know how to handle the dynamic part of the form. i am trying to generate a sort of automatic process but I cannot think of a workable solution.
Any idea?
If by dynamic you refer to xml requests ( ajax ) then you can easily save all the data in session cookies, as this very site does when you're asking a question. :P

Access Drupal webform fields in custom page

I've placed a copy of the webform-submission page in my sites theme folder, and am modifying it to display the submissions pages how I would like. At the moment, to print an elements value, I use:
$submission->data[n]['value'][0]
Where data[n] is specific to the element in the webform. Is there any way I can use something more like $submission->data[element_key]['value'][0] to get the field info. It just makes for much easier reading, especially since I won't be the person maintaining the site.
Thanks.
p.s. this is in Drupal 7, webform 3.0
The $usbmission array is built in the function webform_get_submissions.
Notice that the table which contains the element_key data you're looking for (webform_component table) is not queried in this function.
So if you want that data, you would have to fetch the element_key information yourself and rebuild the $submission array in an implementation of hook_webform_submission_load.

Survey form builder using Jquery PHP?

I'm trying to create a Survey builder wizard that would be embedded in the website.
Users will be able to create their own surveys by dragging and dropping appropriate form elements such as checkboxes, radiobuttons etc
Once the user creates his survey br dragging and dropping the appropriate form elements such as radiocontrol, checkboxes - He should be able to save the created survey and publish it.
While going about doing this I came up with the following questions:
I could build my own drag and drop form building wizard - but is there any open source plugin/code out there so that i dont need to reinvent the wheel ?
How the should the form structure be saved ?
Should the form elements with the associated text be saved in a database (mysql) and rebuilt on the fly when someone accesses the survey link on the mobile ?
Should I be looking at XML/JSON to store the html form structure
Would appreciate any help !
Here is one that we're using now to put a form builder on our client's website.
http://www.botsko.net/blog/2009/04/07/jquery-form-builder-plugin/
The form can be serialized to both JSON and XML.
You can use jQuery UI for the drag and drop operations. I would make use the grid functionality provided.
To save the form I'd make standardized representations of the elements in a JSON format and save those.
This representation should include the left and top css attributes (for positioning) and a subset of styles and attributes which your users can assign their input fields.
Just for completeness
At the time I posted the question, this was not available or else I would have opted for this to build the front end :
http://getfuelux.com/formbuilder.html

Categories