Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

Form with dynamic fields?

  • 19-07-2012 02:03PM
    #1
    Closed Accounts Posts: 27,856 ✭✭✭✭


    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: 12,027 ✭✭✭✭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