B4J Question Cannot get Data from a form which was working

Peter Lewis

Well-Known Member
Licensed User
Longtime User
Hi,
I have been looking for a few hours why this worm will not save data.
I checked on the HTML side and it looks perfect. How I did this was to past the form to https://httpbin.org/post
The result is

When I post to the server, I can see the length is different depending on what I type


But the map is not filled. I used this code to read it before and populate the DB

B4X:
    Dim query As String = utils.prepareInsertQuery($"
    INSERT INTO [ledposter].[dbo].[malls](
     [mallID]
    ,[mallName]
    ,[province]
    ,[city]
    ,[postalcode]
    ,[phone]
    ,[email]
    ,[ownerID]
    ,[suburb]
    ,[description]
    ,[retailshops]
    ,[posters]
    ,[status]
      ,[mtraffic]
 
            )"$)
    
    Dim guidST As JavaObject
    guidST.InitializeStatic("java.util.UUID")
    Dim guid As JavaObject = guidST.RunMethod("randomUUID",Null)
    Dim guidStr As String = guid.RunMethod("toString",Null)
    
        Dim params(query.Length - query.Replace("?","").Length) As String
    params(0) = guidStr
    params(1) = req.GetParameter("mallnameInput")
    params(2) = req.GetParameter("provinceSelect")
    params(3) = req.GetParameter("municipalitySelect")
    params(4) = req.GetParameter("postalcodeInput")
    params(5) = req.GetParameter("phoneInput")
    params(6) = req.GetParameter("emailInput")
    params(7) = req.GetParameter("ownerSelect")
    params(8) = req.GetParameter("suburbSelect")
    params(9) = req.GetParameter("descriptionTextarea")
    params(10) = req.GetParameter("retailshopsInput")
    params(11) =req.GetParameter("postersInput")
    params(12) = "unknown"
    params(13) ="0"
 
    sql.execnonquery2(query,params)

It seems like the data is coming through but I cannot find the method of extracting it

<form method="POST" action="/malladd">
</form>

Maybe it is a Sunday problem.

I am using HTMX to swap out the Select Areas and also to SWAP out the Searchable Fields.. I tried Choices.js but found it was not working for me as I had more than one field to use the plugin and it would not support that. So I eventually used datatables



B4X:
                                    <div class="col-lg-4">
                                                                            <label for="provinceSelect">Province</label>
                                                                            <br>
                                            <input list="provinceSelectlist" name = "provinceSelect" autocomplete="nope" hx-get="/muni"  hx-target="#municipalitySelectlist" placeholder="Search Province">               
                                                                            <datalist id="provinceSelectlist">
                                                                                  <#list  provincetable as provincetables>
                                                                                        <option value="${provincetables.province}" >
                                                                                  </#list>
                                                                            </datalist>
                                                                                    
                                                                            
                                                                        </div>
                                                                                            
                                                        <!-- State -->
                                                                        <div class="col-lg-4">
                                                                        <label for="municipalitySelect">Municipality</label>
                                                                        <br>
                                                                        <input list="municipalitySelectlist" name = "municipalitySelect"  autocomplete="nope" hx-get="/suburb"  hx-target="#suburbSelectlist" placeholder="Search Municipality">
                                                                                
                                                                            <datalist id="municipalitySelectlist">
                                                                                    <#list  municipalitytable as municipalitytables>
                                                                                        <option value="${municipalitytables.city}">
                                                                                    </#list>
                                                                            </datalist>
                                                                                
                                                                            
                                                                        </div>
                                                                        
                                                                        <div class="col-lg-4">
                                                                            <label for="suburbSelect">Suburb</label>
                                                                            <br>
                                                                            <input list="suburbSelectlist" name = "suburbSelect" autocomplete="nope" placeholder="Search Suburb">
                                                                                <datalist id="suburbSelectlist">
                                                                                            <#list  suburbtable as suburbtables>
                                                                                                <option value="${suburbtables.suburb}" >
                                                                                            </#list>
                                                                                </datalist>
                                                                        </div>



Thank you
 
Last edited:
Solution
Thank you to @aeric who spent time with me trying to find the solution
I have narrowed it down to the culprit which I still do not understand why but here it goes.

We added this line at the begin of the handle

B4X:
    Dim params As Map = Req.ParameterMap

It solved the problem which is crazy because we are not using the params variable


If I comment out this line then it saving fields of the form to the database does not work

I really hope there is an explanation because I like to know why, it improves my thought process for future problems.

Peter Lewis

Well-Known Member
Licensed User
Longtime User
Line 30 is giving an error because the input is null

 
Upvote 0

Peter Lewis

Well-Known Member
Licensed User
Longtime User


I put in the simple form and posted it, on the server I got


 
Upvote 0

aeric

Expert
Licensed User
Longtime User
1. I suggest add:
B4X:
Log(req.ParameterMap)
It may not been initialized so all values are empty.

2. Also try to use:
B4X:
Log(req.GetParameter("mallInput"))
* assuming there is an input field with attribute name = "mallInput"
 
Upvote 0

Peter Lewis

Well-Known Member
Licensed User
Longtime User
I took out all the code in the html EXCEPT for the bootstrap and tried again
I took out all the code in the html EXCEPT for the bootstrap and tried again



Same Result

 
Upvote 0

Peter Lewis

Well-Known Member
Licensed User
Longtime User

That was always there

console result

 
Upvote 0

Peter Lewis

Well-Known Member
Licensed User
Longtime User
B4X:
<!--
* Author: Peter Lewis
* Product Name: LED POSTER ADs
* Version: 5
* Website:  https://www.ledposter.co.za
* Contact: support@ledposter.co.za
-->
<!DOCTYPE html>
<html lang="en">

        <head>
             <meta charset="utf-8">
        <title>Dashboard | LED POSTER ADs</title>
          <meta name="viewport" content="width=device-width, initial-scale=1">
            <meta name="description" content="LED Posters high quality media display devices along with the facility to connect to our Advertising platform to earn advertising revenue">
            <meta name="keywords" content="LED Poster, Marketing poster, digital marketing, LED Poster Averts">
            <meta name="author" content="Peter Lewis">

    
        </head>

<body>
    <!-- Begin page -->
    <div class="wrapper">
                <form method="POST" action="/malladd">
                      <input type="hidden" name="province" id="provinceInput" value="TEST">
                      <button type="submit" class="btn btn-primary">Submit</button>
                </form>
                            
   </div>
            <!-- Footer Start -->
             <footer class="footer">
              
            </footer>
            <!-- end Footer -->
    </div>
        <!-- ============================================================== -->
        <!-- End of Main Content -->
        <!-- ============================================================== -->


</body>
</html>

Is now the HTML file , Nothing else



just with a submit button

B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
        #if debug
    Main.templates.clearTemplateCache
    #End If   
    Dim sql As SQL = utils.pool.GetConnection
    Log("clsMallInfoAdd")
    Log("length "&req.ContentLength)
    Log("Type "&req.ContentType)
    Log("Full Request URL "&req.FullRequestURI)
    Log("Input Stream "&req.InputStream)
    Log("Methods "&req.Method)
    Log("Request URI "&req.RequestURI)
    Log("Secure ? "&req.Secure)
    Log(req.ParameterMap)
    Dim root As Map
    root.Initialize
    Log("Mall Name "&req.GetParameter("province"))
    Log("Methods "&req.Method)
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
A little hard to help since we don't see the code in the handle sub or your custom class.
I tested with a simple project here.
 

Attachments

  • ParameterTest.zip
    2 KB · Views: 36
Upvote 1

Peter Lewis

Well-Known Member
Licensed User
Longtime User
A little hard to help since we don't see the code in the handle sub or your custom class.
I tested with a simple project here.
that returns data
<ul>
<li>province: TEST</li>
<li>mallnameInput: Gateway</li>
</ul>
Mall name: Gateway

 
Upvote 0

Peter Lewis

Well-Known Member
Licensed User
Longtime User
A little hard to help since we don't see the code in the handle sub or your custom class.
I tested with a simple project here.
I do not understand how but all of a sudden it is working again with my original code. I did leave your sub inside which I will take out 1 line at a time or could it be IRAN hackers


 
Upvote 0

Peter Lewis

Well-Known Member
Licensed User
Longtime User
Thank you to @aeric who spent time with me trying to find the solution
I have narrowed it down to the culprit which I still do not understand why but here it goes.

We added this line at the begin of the handle

B4X:
    Dim params As Map = Req.ParameterMap

It solved the problem which is crazy because we are not using the params variable


If I comment out this line then it saving fields of the form to the database does not work

I really hope there is an explanation because I like to know why, it improves my thought process for future problems.
 
Last edited:
Upvote 0
Solution
Cookies are required to use this site. You must accept them to continue using the site. Learn more…