Form input not working.

66 views
Skip to first unread message

Maurice Waka

unread,
Jul 6, 2018, 10:49:28 AM7/6/18
to web2py-users
Hi.
Am trying out this html to get user input into the database and retrieve the same/some other data from the same database. At the section below, I cant seem to submit the user input, what could be the problem and how do I correct it.
 <form action="" method="GET" class="hidden">
                                   
<select data-conv-question="Hello! I'm a bot created from a HTML form. Can I show you some features? (this question comes from a select)">
                                       
<option value="yes">Yes</option>
                                       
<option value="sure">Sure!</option>
                                   
</select>
                                   
<input type="text" name="message" data-conv-question="Alright! First, type one word  or ask a question.|Okay! you can type one word  or ask a question.">
                                   
<input type="text" data-conv-question="{{=responses}}" data-no-answer="true">
                                   
<input type="text" data-conv-question="This plugin supports multi-select too. Let's see an example." data-no-answer="true">
                                   
<select name="programmer" data-callback="storeState" data-conv-question="So, are you a programmer? (this question will fork the conversation based on your answer)">
                                       
<option value="yes">Yes</option>
                                       
<option value="no">No</option>
                                   
</select>                                  
                                   
<select data-conv-question="This is it! If you like me, consider donating! If you need support, contact me. When the form gets to the end, the plugin submits it normally, like you had filled it." id="">
                                       
<option value="">Awesome!</option>
                                   
</select>
                               
</form>
the controller code is this:
def search():
    form
= SQLFORM(Post, formstyle='table3cols').process()
    code
..
    responses
= responses()
   
return dict(form=form, responses=responses)
Post = db.define_table('post',
                       
Field('author', 'reference auth_user', default=auth.user_id, writable=False, readable=False),
                       
Field('message', 'text', requires=IS_NOT_EMPTY(), default ='', notnull=False),
                       auth
.signature
                       
)

Anthony

unread,
Jul 6, 2018, 11:11:44 AM7/6/18
to web2py-users
Your HTML will submit form data to web2py via the URL query string (due to using the GET method), but your controller code is not set up to properly process the form data. Instead, it defines a SQLFORM that does not exactly match the HTML form.


Anthony

Maurice Waka

unread,
Jul 6, 2018, 12:49:23 PM7/6/18
to web...@googlegroups.com
I've changed from method='GET' to method ='POST', name=message ' (the table name) etc. But I seem to have an issue with the highlighted part. It's still not posting. Could you please give an example of how this can work? 
<form action="" enctype="multipart/form-data" method="POST" class="hidden">
                                    <select data-conv-question="Hello! I'm a bot created from a HTML form. Can I show you some features? (this question comes from a select)">
                                        <option value="yes">Yes</option>
                                        <option value="sure">Sure!</option>
                                    </select>
                                    <input type="text" name="message" data-conv-question="Alright! First, type one word e.g. 'exercise', or ask a question.|Okay! you can type one word e.g. 'Soy', or ask a question.">
                                    <input type="text" data-conv-question="{{=reports}}" data-no-answer="true">
                                    <input
Regards 

--
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/ohTduB-ui7U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Anthony

unread,
Jul 6, 2018, 1:56:39 PM7/6/18
to web2py-users
On Friday, July 6, 2018 at 12:49:23 PM UTC-4, Maurice Waka wrote:
I've changed from method='GET' to method ='POST', name=message ' (the table name) etc. But I seem to have an issue with the highlighted part. It's still not posting. Could you please give an example of how this can work? 
<form action="" enctype="multipart/form-data" method="POST" class="hidden">
                                    <select data-conv-question="Hello! I'm a bot created from a HTML form. Can I show you some features? (this question comes from a select)">
                                        <option value="yes">Yes</option>
                                        <option value="sure">Sure!</option>
                                    </select>
                                    <input type="text" name="message" data-conv-question="Alright! First, type one word e.g. 'exercise', or ask a question.|Okay! you can type one word e.g. 'Soy', or ask a question.">

What exactly is the problem with that line? What are you expecting and what do you observe?

Note, if you're using SQLFORM, you'll need to include {{=form.custom.end}} to make sure the hidden formname and formkey fields are included. Please read the documentation.

Anthony

Maurice Waka

unread,
Jul 7, 2018, 6:34:01 AM7/7/18
to web...@googlegroups.com
I managed to go to the basics and got some progress:
def searches():
    form = FORM(INPUT(_name='message'), INPUT(_type='submit'))
    code = request.vars.message
    return dict(code=code)

view:
<form enctype = "multipart/form-data" action = "{{= URL()}}" method = "post" class="hidden">
                                    <select data-conv-question="Hello! I'm a bot created from a HTML form. Can I show you some features? (this question comes from a select)">
                                        <option value="yes">Yes</option>
                                        <option value="sure">Sure!</option>
                                    </select>
                                    <input type="text" name="message" data-conv-question="Alright! First, type one word e.g. 'exercise', or ask a question.|Okay! you can type one word e.g. 'Soy', or ask a question.">
                                    <input type="text" data-conv-question="{{=code}}" data-no-answer="true">                                    
                                </form>

However, as a test, when retrieving data to controller, the request.vars does not give me the immediate user posted data, instead the previous data posted. For example, if the user posts 'abcd', with the previous post having been '1234', I'll get '1234' returned and not 'abcd'.
Is there a way of cleaning up request.vars and getting the CURRENT posted data?
Thanks for the help, God bless!

--

Maurice Waka

unread,
Jul 7, 2018, 6:02:55 PM7/7/18
to web...@googlegroups.com
Hi.
I'll need your help. Am still stuck at this. I note that only when I refresh the page, will I get the latest 'request.vars.value' gets posted to the controller.
  1. Is there a way of auto-refreshing the controller?
  2. Is there a better method that this......Following your suggested option of {{form.custom.end}} i ended up with a blank page instead, hence going to the basics.
  3. My aim is that when a user posts input, I retrieve it from what ever means....request.vars etc,  then send to the functions to process..
Kind regards

Anthony

unread,
Jul 7, 2018, 6:26:27 PM7/7/18
to web2py-users
First, read the documentation at http://web2py.com/books/default/chapter/29/07/forms-and-validators, as you do not appear to be following it. If for some reason you do not want to use the built-in form functionality, just create an HTML form, and in the action that receives the submission, the submitted form values will be available in request.vars -- from there, you can do whatever you want with the data.

Anthony
On Friday, July 6, 2018 at 12:49:23 PM UTC-4, Maurice Waka wrote:
I've changed from method='GET' to method ='POST', name=message ' (the table name) etc. But I seem to have an issue with the highlighted part. It's still not posting. Could you please give an example of how this can work? 
<form action="" enctype="multipart/form-data" method="POST" class="hidden">
                                    <select data-conv-question="Hello! I'm a bot created from a HTML form. Can I show you some features? (this question comes from a select)">
                                        <option value="yes">Yes</option>
                                        <option value="sure">Sure!</option>
                                    </select>
                                    <input type="text" name="message" data-conv-question="Alright! First, type one word e.g. 'exercise', or ask a question.|Okay! you can type one word e.g. 'Soy', or ask a question.">

What exactly is the problem with that line? What are you expecting and what do you observe?

Note, if you're using SQLFORM, you'll need to include {{=form.custom.end}} to make sure the hidden formname and formkey fields are included. Please read the documentation.

Anthony

--
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/ohTduB-ui7U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.

Maurice Waka

unread,
Jul 9, 2018, 4:05:38 AM7/9/18
to web...@googlegroups.com
All I needed is to pass a current value to the db/controller from the html. After much working, I found that using this was one the best options:
<script>
    jQuery('#myform').submit(function() {
        ajax('{{=URL('view_searche')}}',
            ['message'], 'chat');
        return false;
    });
</script>

To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
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/ohTduB-ui7U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.

Dave S

unread,
Jul 9, 2018, 6:11:04 AM7/9/18
to web2py-users


On Monday, July 9, 2018 at 1:05:38 AM UTC-7, Maurice Waka wrote:
All I needed is to pass a current value to the db/controller from the html. After much working, I found that using this was one the best options:
<script>
    jQuery('#myform').submit(function() {
        ajax('{{=URL('view_searche')}}',
            ['message'], 'chat');
        return false;
    });
</script>

The issue is that you are trying to do this without reloading the page?

I think we previously discussed the LOAD() helper and the ajax() function 
I don't remember why those didn't work for you., but I think that would have been the simplest route.

/dps

Maurice Waka

unread,
Jul 9, 2018, 6:41:20 AM7/9/18
to web...@googlegroups.com
yes, without reload.
Am trying out various templates to fit into web2py rules.
Please bear with my incompetence, am just looking to get a prototype work,till I get a professional.
Thanks. 
Am working on it.

Reply all
Reply to author
Forward
0 new messages