Note, you don't necessarily need to do this with two separate actions:

def copy_record():
    form = FORM('Enter record ID:', INPUT(_name='id', _type='integer'),
                INPUT(_type='submit', _value='Submit'))
    if request.post_vars.id:
        record = db.table1(request.post_vars.id)
        if record:
            db.table2.insert(**db.table2._filter_fields(record))
            response.flash = 'The record was copied'
        else:
            response.flash = 'A record with ID %s does not exist.' % request
.post_vars.id
    return dict(form=form)

Then in the copy_record.html view, you just need:

{{=form}}

Anthony

On Wednesday, August 22, 2012 2:12:45 AM UTC-4, Khalil KHAMLICHI wrote:
>
> 1) controller page1: controllers/default.py
>
> def page1:
> return dict()
>
> 2) view page1: views/default/page1.html
>
> page1.html content :
>
> <form name="text_form" action="page2.html" method="get">
>  Please Enter ID: <input type="text" name="EneteredID" />
> <input type="submit" value="Submit" />
> </form>
>
> 3) controller page2: controllers/default.py
>
> def page2():
> EnteredID = request.vars['EnteredID']
> # 1 - check if record exists 
> record = db(db.YourTableNameHere.ID == EnteredID).select()[0]
> if len(record):
> # 2 insert it into a second table
> db(db.SecondTableName).insert(field1=record.field1, field2=record.field2, 
> field3=record.field3 )
> return dict( result='Success' ) 
> else:
> return dict( result='Record Not Found')
>
> I believe you can build on top of this.
>
>
> On Wed, Aug 22, 2012 at 6:52 AM, Amit <[email protected] 
> <javascript:>>wrote:
>
>> Hi,
>> I generated one custom html file which is having one text field where 
>> user has to enter id and one submit button.
>>
>> I have to use it in following manner:
>> 1. User has to enter the id and press the submit button
>> 2. after pressing submit button, id value has to be validated in xyz 
>> table.
>> 3. first it has to validate whether entered id is available in xyz table 
>> or not, if not available then it has to notify the user about it
>> 4. if id is available in xyz table then it will fetch the record of id 
>> from xyz table and insert it to another table called abc table.
>>
>> problem facing:
>> I have to add this html to my web2py project and achieve the above 
>> functionality  , Can anybody help me to provide the solution how to use 
>> custom html and database interaction with it?
>>
>> -- 
>>  
>>  
>>  
>>
>
>

-- 



Reply via email to