Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2023-03-17 17:37:35

lindabb
Member
Registered: 2023-02-17
Posts: 111

input form maker

hello,
I understand, this cms tools, and may not had need to make such tools. asking it doesn’t heart!

is there any plugin like dynamic input form maker from given table (depending on column type and length),
now smd_bio works same way, creates input form from new added fields on fly.

What I’m looking for like
<txp:formaker tablename=“products” , allowed_fields=“name, price, size, color” p_key=“id” >

Thank you

Offline

#2 2023-03-17 18:33:15

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: input form maker

Not out of the box, but I can imagine (etc|smd)_query reading the information schema and pulling appropriate input fields from some conditional form(s) or variable(s) that you’ll need to provide:

<txp:etc_query data="SELECT * FROM `INFORMATION_SCHEMA`.`COLUMNS`
    WHERE `TABLE_SCHEMA`='your_db' AND `TABLE_NAME`='products'
    AND COLUMN_NAME IN('name', 'price', 'size', 'color')"
>
    <txp:output_form form="{DATA_TYPE?}" name="{COLUMN_NAME?}" length="{CHARACTER_MAXIMUM_LENGTH?}" value="{COLUMN_DEFAULT?}" />
    <!-- contains some input/textarea/etc field -->
</txp:etc_query>

That’s what could be inside varchar form:

<input name='<txp:yield name="name" />' value='<txp:yield name="value" trim="'" escape />' maxlength='<txp:yield name="length" />' />

Offline

#3 2023-03-18 12:39:46

lindabb
Member
Registered: 2023-02-17
Posts: 111

Re: input form maker

Thank you,
I tried this example for default existed table, but sorry I’m missing something , I don’t understand how works:

<txp:etc_query data="SELECT * FROM `INFORMATION_SCHEMA`.`COLUMNS`
    WHERE `TABLE_NAME`='textpattern'
    AND COLUMN_NAME IN('ID','Posted','Expires','AuthorID','LastMod','LastModID','Title','Title_html')">

    <txp:output_form form="{DATA_TYPE?}" length="{CHARACTER_MAXIMUM_LENGTH?}" ... />
    <!-- contains some input/textarea/etc field -->
<input name='<txp:yield name="Title" />' value='<txp:yield name="value" trim="'" escape />' maxlength='<txp:yield name="length" />' />
</txp:etc_query>

any idea ?

Thank you

Offline

#4 2023-03-18 12:55:52

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: input form maker

That’s quite easy, try this first:

<txp:etc_query data="SELECT * FROM `INFORMATION_SCHEMA`.`COLUMNS`
    WHERE `TABLE_SCHEMA`='your_db' AND `TABLE_NAME`='products'
    AND COLUMN_NAME IN('name', 'price', 'size', 'color')"
>
    <input name="{COLUMN_NAME?}" maxlength="{CHARACTER_MAXIMUM_LENGTH?}" value="{COLUMN_DEFAULT?}" />
</txp:etc_query>

This should give you four text input fields. But you would rather use number type inputs for numeric fields, right? That’s where {DATA_TYPE?} is useful, to detect the field’s type and construct inputs accordingly. In my example, I thought of creating a form for each data type (varchar, int, etc) and call it to construct appropriate inputs.

Offline

#5 2023-03-18 14:32:24

lindabb
Member
Registered: 2023-02-17
Posts: 111

Re: input form maker

Thank you, this one worked: <input name=”{COLUMN_NAME?}” maxlength=”{CHARACTER_MAXIMUM_LENGTH?}” value=”{COLUMN_DEFAULT?}” />

Offline

Board footer

Powered by FluxBB