Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Form with dynamic fields?

  • 19-07-2012 2:03pm
    #1
    Closed Accounts Posts: 27,857 ✭✭✭✭


    Hey folks,

    I'm just working on a small project for my dad at the moment, which is a kind of repair/sales form that he might use for work. Essentially the fields/flow is as follows:
    1. Select a customer from a dropdown, and several related fields are automatically populated
    2. Choose which of a few checkbox options are applicable
    3. Add a number of products/parts/items to a list for that 'call'

    #1 is grand

    #2 - I'm wondering what is the best way to store selected checkboxes in a single field in a table. This actually seems like a good solution, but I'd like to follow best practice.

    [PHP]$colors = mysql_real_escape_string(implode(',', $_POST));[/PHP]

    I'll obviously need to be able to access and view the saved form again, so the explode() function should do that.

    #3 - Would this be the same kind of deal actually? I would probably have a dropdown menu, and if an item is selected I'll use AJAX to query the 'parts' table and get the price, etc. But really I just need to store the item id, don't I? In which case the above solution would work again.

    Unless it's really horrific practice (which I suspect it is), I'd like to keep each 'form' / submission in the one table rather than having another table with e.g. id - form_id - part_id

    Thanks


Comments

  • Registered Users, Registered Users 2 Posts: 11,989 ✭✭✭✭Giblet


    You could use a bitflags

    So if you have
    RED = 1,
    GREEN = 2,
    WHITE = 4,
    BLACK = 8
    

    If the user stored green + black, the bitfield value would be 10 which can be stored.
    Using bitwise operations, you can figure out that 10 = BLACK + GREEN


Advertisement