Then, in your template:
{{extend 'layout.html'}}
{{=form.custom.begin}}
<ul>
<li>{{=form.custom.label.Category_name}}: {{=form.custom.widget.
Category_name}}</li>
<li>{{=form.custom.label.Event_id}}: {{=form.custom.widget.Event_id
}}</li>
</ul>
{{=form.custom.submit}}
{{=form.custom.end}}
You can read more about it
here:
http://web2py.com/books/default/chapter/29/07/forms-and-validators#Custom-forms
-Jim
On Wednesday, July 8, 2020 at 10:16:56 AM UTC-5, Anusha Narayan wrote:
>
> Thankyou , this surely helps.
> But what if we want to custom our form using html and css?
>
> On Wed, 8 Jul 2020, 7:03 pm Jim S, <[email protected] <javascript:>>
> wrote:
>
>> Here is how I'd do it:
>>
>> Controller:
>> def category():
>> db.category.name.default = request.args(0)
>> form=SQLFORM(db.category)
>> return dict(form=form)
>>
>> Template:
>> {{extend 'layout.html'}}
>> {{=form}}
>>
>> There are a couple of issues in your example
>>
>> 1. You're using SQLFORM to create a form, but then you aren't doing
>> anything with it. You need to pass it to your template for it to be useful.
>> 2. The else portion of the if form.process().accepted is executed
>> anytime you call the controller and haven't submitted the form. Therefore,
>> on your initial display of the form, your error message will display.
>>
>> I hope this helps.
>>
>> -Jim
>>
>> On Tuesday, July 7, 2020 at 7:33:30 PM UTC-5, AGRogers wrote:
>>>
>>> OK. After you declare the form but before you process it you can set the
>>> form.vars.FieldName property. I think that might help.
>>>
>>> On Wed, 8 Jul 2020, 4:36 am Anusha Narayan, <[email protected]> wrote:
>>>
>>>> Yeah! The first question, is what I am talking about.
>>>>
>>>> On Mon, 6 Jul 2020, 8:56 pm AGRogers, <[email protected]> wrote:
>>>>
>>>>> Do you mean you want to set the EVENT_ID so that it's already selected
>>>>> when the form opens?
>>>>>
>>>>> Or are you saying that after you select the Event and submit the form
>>>>> you get an error?
>>>>>
>>>>> On Sat, 4 Jul 2020, 3:27 pm Anusha Narayan, <[email protected]>
>>>>> wrote:
>>>>>
>>>>>> *The code of my model db.py is:*
>>>>>>
>>>>>> db.define_table(
>>>>>> 'event_table',
>>>>>> Field('event_name'),
>>>>>> Field('organizer_name'),
>>>>>> )
>>>>>>
>>>>>> db.define_table('category',
>>>>>> Field('Category_name',requires=IS_NOT_EMPTY()),
>>>>>> Field('Event_id',db.event_table)
>>>>>> )
>>>>>>
>>>>>> *The controller looks like:*
>>>>>>
>>>>>> def category():
>>>>>>
>>>>>> form=SQLFORM(db.category)
>>>>>> if form.process().accepted:
>>>>>> response.flash='form has accepted'
>>>>>> else:
>>>>>> response.flash='form has errors'
>>>>>> return dict()
>>>>>>
>>>>>>
>>>>>> *The code for the view (default/category.html) is:*
>>>>>>
>>>>>> {{extend 'layout.html'}}
>>>>>>
>>>>>>
>>>>>>
>>>>>> <form action="#" enctype="multipart/form-data" method="post"><ul>
>>>>>>
>>>>>> <li>category name: <input name="Category_name"
>>>>>> value="{{=request.args(0)}}"/></li>
>>>>>> <li>event_id type: <input name="Event_id" ></li></ul>
>>>>>> <input type="submit" value="Submit" />
>>>>>> </form>
>>>>>>
>>>>>>
>>>>>> *(Here I am trying to pass the event id through the request argument of
>>>>>> the URL. But when I submit the form, it says "form has errors". Why is
>>>>>> that happening? I am not able to understand.?*
>>>>>>
>>>>>> --
>>>>>> Resources:
>>>>>> - http://web2py.com
>>>>>> - http://web2py.com/book (Documentation)
>>>>>> - http://github.com/web2py/web2py (Source code)
>>>>>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>>>>>> ---
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "web2py-users" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>> send an email to [email protected].
>>>>>> To view this discussion on the web visit
>>>>>> https://groups.google.com/d/msgid/web2py/38a3a4ba-7887-415a-8409-f5f28170d178o%40googlegroups.com
>>>>>>
>>>>>> <https://groups.google.com/d/msgid/web2py/38a3a4ba-7887-415a-8409-f5f28170d178o%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>> .
>>>>>>
>>>>> --
>>>>> Resources:
>>>>> - http://web2py.com
>>>>> - http://web2py.com/book (Documentation)
>>>>> - http://github.com/web2py/web2py (Source code)
>>>>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>>>>> ---
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "web2py-users" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to [email protected].
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/web2py/CACWMBMNsEm9rXYFhd7e8Bh6jK9wix%2ByUdZ5BunMT%3Dnef92mGPg%40mail.gmail.com
>>>>>
>>>>> <https://groups.google.com/d/msgid/web2py/CACWMBMNsEm9rXYFhd7e8Bh6jK9wix%2ByUdZ5BunMT%3Dnef92mGPg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>> --
>>>> Resources:
>>>> - http://web2py.com
>>>> - http://web2py.com/book (Documentation)
>>>> - http://github.com/web2py/web2py (Source code)
>>>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>>>> ---
>>>> You received this message because you are subscribed to the Google
>>>> Groups "web2py-users" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/web2py/CAPf%3DStg%3DQEP%2B5VCTBpuohbSVEjY%3DueYvjzBRsJzseQ4nKTBWWA%40mail.gmail.com
>>>>
>>>> <https://groups.google.com/d/msgid/web2py/CAPf%3DStg%3DQEP%2B5VCTBpuohbSVEjY%3DueYvjzBRsJzseQ4nKTBWWA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> --
>> Resources:
>> - http://web2py.com
>> - http://web2py.com/book (Documentation)
>> - http://github.com/web2py/web2py (Source code)
>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "web2py-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/web2py/119b2c41-ae90-4684-aaea-3ebc5f6fde53o%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/web2py/119b2c41-ae90-4684-aaea-3ebc5f6fde53o%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/web2py/14df2ad5-942b-478c-b911-611351cce6cao%40googlegroups.com.