Pass/Receive args contains "&" in the value

85 views
Skip to first unread message

Omi Chiba

unread,
Jan 13, 2021, 2:24:22 PM1/13/21
to web2py-users
Hi, the following works fine when there is no symbol such as "&" in the field value. How can we pass and receive the parameters which contains "&"..etc.? 

View - customer_index

    <td class="row_buttons"><a href="{{=URL('customer_view',args=
[list.TKDIID,list.TKDICD])}}" class="btn"><i class="icon-search"></i> View</a>

Controller - default.py

def customer_index():
    response.title = 'List'
    response.subtitle = 'Customer Code'
    
    form=SQLFORM.factory(Field('search'))
    form.custom.widget.search['_class'] = 'input-medium search-query'
    form.custom.submit['_value'] = 'Search'
    form.custom.submit['_class'] = 'btn'
    
    if form.accepts(request):
        key=form.vars.search.upper() + "%"
        query = (db.EDXTKF00.TKDIID.like(key)) | (db.EDXTKF00.TKDICD.like(key))  
    else:
        query = db.EDXTKF00.TKDIID!=""
    
    # Paging plugin        
    paginate_selector = PaginateSelector(anchor='main')
    paginator = Paginator(paginate=paginate_selector.paginate, 
                          extra_vars={'v':1}, anchor='main',
                          renderstyle=True) 
    paginator.records = db(query).count()
    paginate_info = PaginateInfo(paginator.page, paginator.paginate, paginator.records)
    # End Paging plugin...
    
    lists=db(query).select(db.EDXTKF00.TKDIID,db.EDXTKF00.TKDICD,db.EDXTKF00.TKTKSC,db.EDXTKF00.TKTKCD,db.EDXTKF00.TKDMCD,orderby=[db.EDXTKF00.TKDIID,db.EDXTKF00.TKDICD],limitby=paginator.limitby())
    return dict(form=form,lists=lists,paginator=paginator,paginate_selector=paginate_selector, paginate_info=paginate_info)

def customer_view():
    response.title = 'View'
    response.subtitle = 'Customer Code'
    
    request.args(0) or redirect (URL('customer_index'))
    record = db.EDXTKF00(db.EDXTKF00.TKDIID==request.args(0) and db.EDXTKF00.TKDICD==request.args(1))
    
    if record != None:
        form = SQLFORM(db.EDXTKF00,record, readonly=True)
    else:
        redirect(URL('customer_index'))  
        
    return dict(form=form)



Omi Chiba

unread,
Jan 13, 2021, 10:03:54 PM1/13/21
to web2py-users
In another word, how I can encode and decode the value including special characters such as "&".

Jim S

unread,
Jan 18, 2021, 6:58:43 PM1/18/21
to web2py-users
Can you wrap it in an XML function?

<td class="row_buttons"><a href="{{=URL('customer_view',args=
[XML(list.TKDIID),XML(list.TKDICD)])}}" class="btn"><i class="icon-search"></i> View</a>

Omi Chiba

unread,
Jan 18, 2021, 10:16:04 PM1/18/21
to web2py-users
JIm,

Thank you for your reply! I will test it later this week and let you guys know.

Omi Chiba

unread,
Jan 20, 2021, 4:36:43 PM1/20/21
to web2py-users
I added XML. It doesn't show the error but cannot get the value and shows the records...  should we changed the controller side too?

View
 <td class="row_buttons"><a href="{{=URL('enduser_view',args=[XML(list.USDIID),XML(list.USDICD),XML(list.USYUB5),XML(list.USTSKJ)])}}" class="btn"><i class="icon-search"></i> View</a>

Controller
    record = db.EDXUSF00(db.EDXUSF00.USDIID==request.args(0) and db.EDXUSF00.USDICD==request.args(1) and db.EDXUSF00.USYUB5==request.args(2) and db.EDXUSF00.USTSKJ==request.args(3))

Jim Steil

unread,
Jan 20, 2021, 5:47:17 PM1/20/21
to web...@googlegroups.com
I don't think it will help to change the controller side.

In the controller can you print out the values and also print out the XML(value) and see what the difference is?

-Jim

--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/O1Mv_tbFbcw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/93e8a999-e0be-4e33-bc91-43e5451edee7n%40googlegroups.com.

Omi Chiba

unread,
Jan 20, 2021, 7:49:48 PM1/20/21
to web2py-users
I'm not sure how to check...

This is my controller for view page

def enduser_view():
    response.title = 'View'
    response.subtitle = 'End User Code'
    
    request.args(0) or redirect (URL('enduser_index'))
    record = db.EDXUSF00(db.EDXUSF00.USDIID==request.args(0) and db.EDXUSF00.USDICD==request.args(1) and db.EDXUSF00.USYUB5==request.args(2) and db.EDXUSF00.USTSKJ==request.args(3))
    
    if record != None:
        form = SQLFORM(db.EDXUSF00,record, readonly=True)
    else:
        redirect(URL('enduser_index'))  
        
    return dict(form=form)



Jim Steil

unread,
Jan 20, 2021, 8:01:07 PM1/20/21
to web...@googlegroups.com
I thought you were trying to get it working in this html tag:

<td class="row_buttons"><a href="{{=URL('customer_view',args=[list.TKDIID,list.TKDICD])}}" class="btn"><i class="icon-search"></i> View<

I don't see the 'list' variable in the controller...

Where is that coming from?

-Jim

Omi Chiba

unread,
Jan 20, 2021, 8:03:37 PM1/20/21
to web2py-users
here's the controller for enduser_index view. It's like I have this index view to list and lick "View" button to pass the variable and go to enduser_view page.

def enduser_index():
    response.title = 'List'
    response.subtitle = 'End User Code'
    
    form=SQLFORM.factory(Field('search'))
    form.custom.widget.search['_class'] = 'input-medium search-query'
    form.custom.submit['_value'] = 'Search'
    form.custom.submit['_class'] = 'btn'
    
    if form.accepts(request):
        key=form.vars.search.upper() + "%"
        query = (db.EDXUSF00.USDIID.like(key)) | (db.EDXUSF00.USDICD.like(key)) | (db.EDXUSF00.USTSKJ.like(key))
    else:
        query = db.EDXUSF00.USDIID!=""
    
    # Paging plugin        
    paginate_selector = PaginateSelector(anchor='main')
    paginator = Paginator(paginate=paginate_selector.paginate, 
                          extra_vars={'v':1}, anchor='main',
                          renderstyle=True) 
    paginator.records = db(query).count()
    paginate_info = PaginateInfo(paginator.page, paginator.paginate, paginator.records)
    # End Paging plugin...
    
    lists=db(query).select(db.EDXUSF00.USDIID,db.EDXUSF00.USDICD,db.EDXUSF00.USYUB5,db.EDXUSF00.USTSKJ,db.EDXUSF00.USUSCD,orderby=[db.EDXUSF00.USDIID,db.EDXUSF00.USDICD,db.EDXUSF00.USYUB5,db.EDXUSF00.USTSKJ],limitby=paginator.limitby())
    return dict(form=form,lists=lists,paginator=paginator,paginate_selector=paginate_selector, paginate_info=paginate_info)
    


Jim Steil

unread,
Jan 20, 2021, 8:35:56 PM1/20/21
to web...@googlegroups.com
So, if you would do a for look around 'lists' and print out the field values, what would that look like?  Also, is there a difference if you also print it out with the XML function wrapped around it?

Omi Chiba

unread,
Jan 20, 2021, 9:36:24 PM1/20/21
to web2py-users
ok, so this is four parameters I'm passing..

J2831

AL04

36105

HYUNDAI MOTOR MANUFACTURI

then list.xxx or XML(list.xxx) actually shows the same result. It replaced blank with "_"... that's why I failed to get the data from the database because the original value doesn't have "_". I also tried the with "&" in the company name and it failed to display the page because of "&"

J2831

AL04

36105

HYUNDAI_MOTOR_MANUFACTURI



Jim Steil

unread,
Jan 20, 2021, 9:52:04 PM1/20/21
to web...@googlegroups.com
So, are you trying to pass a company name through a URL?  Seems to me that would be problematic.  

If that is what you're doing maybe you need to look at urllib unquote_plus.  I use that in some cases to build valid URLs where the text can be unpredictable.

Is there anything else you could pass other than a name to uniquely identify the company in your url?

Or, maybe I'm not following what you're trying to do here.

-Jim


Omi Chiba

unread,
Jan 20, 2021, 10:00:37 PM1/20/21
to web2py-users
>So, are you trying to pass a company name through a URL?  Seems to me that would be problematic. 
Yes, that's what I'm trying and I was hoping there is a easy fix. 

Thank you for your help!  I think I will stop here for now. 
Reply all
Reply to author
Forward
0 new messages