URL vs Form submit syntax

Forum to discuss the Web client version of Servoy.

URL vs Form submit syntax

Postby Westy » Fri Sep 12, 2014 5:13 pm

The following URL submits a company_name:
http://ipaddress/servoy-webclient/ss/s/solutionname/m/methodname/a/company_name=Abaco

What is the syntax to do the same using a web page submit? How should the following be changed?

Code: Select all
<form  method="post" action="http://ipaddress/servoy-webclient/ss?s=solutionname&m=methodname&a=">
      <label for="name">Company Name:<br></label>
           <input name="company_name" value="ABC Company" type="text"  /><br><br>

        <input type="submit" value="Submit"  />
</form>

Dean
Westy
 
Posts: 852
Joined: Fri Feb 13, 2004 5:27 am
Location: Lynnfield, Massachusetts USA

Re: URL vs Form submit syntax

Postby david » Fri Sep 12, 2014 8:46 pm

One way:

Code: Select all
<!DOCTYPE html><html><head>

</head>
<body>

<form id="myForm">
      <label for="name">Company Name:<br></label>
      <input name="company_name" value="ABC Company" type="text"  /><br><br>
      <input type="button" value="Submit" onclick="myFunction();"  />
</form>

<script>
function myFunction() {
   
   var baseURL = "http://ipaddress/servoy-webclient/ss/s/solutionname/m/methodname/a/company_name=",
       companyValue = document.getElementsByName('company_name')[0].value;
   
   if (companyValue) {
      companyValue = encodeURIComponent(companyValue)

      // send browser to new url
      console.log(baseURL + companyValue);
      window.location.href = baseURL + companyValue;
   }

}
</script>

</body>
</html>
David Workman, Kabootit

Image
Everything you need to build great apps with Servoy
User avatar
david
 
Posts: 1727
Joined: Thu Apr 24, 2003 4:18 pm
Location: Washington, D.C.

Re: URL vs Form submit syntax

Postby sovanm » Fri Sep 12, 2014 11:03 pm

Hello,

Another way to submit a form is by using Web Service.

For creating a method to which data will be posted from web page, we have to create a form and then create a method in that with name ws_create.

Code: Select all
/**
* @properties={typeid:24,uuid:"953E3577-A6FB-45F6-B9F2-0C856795E21E"}
*/
function ws_create(content){
   
   application.output('Data posted : ' + content);
   return null;
}


Then in your webpage you have to submit the page using ajax.

Code: Select all
<!DOCTYPE html><html><head>

</head>

<body>

<form id="myForm">
      <label for="name">Company Name:<br></label>
      <input name="company_name" value="ABC Company" type="text"  /><br><br>
      <input type="button" value="Submit" onclick="myFunctionWithWebService();"  />
</form>

<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.8.0.js"></script>

<script>

function myFunctionWithWebService() {
 
   var companyValue = document.getElementsByName('company_name')[0].value;
   
   if (companyValue) {

      $.ajax({url:'http://localhost:8080/servoy-service/rest_ws/<solution_name>/<form_name>/',
      contentType: 'application/json',
      type:'POST',
      data: JSON.stringify(companyValue),
      dataType: 'json',
      success: function(data) {
      alert('success');
      },
      error: function(){
      alert('fail');
      }
      });
   }

}

</script>

</body>
</html>


Please make sure to add the Jquery file if it not added in the web page.

More information on web service : Servoy Web Service.

Hope this will help you.

Thanks
sovanm
 
Posts: 99
Joined: Fri Oct 28, 2011 1:55 pm
Location: Bhubaneswar, India

Re: URL vs Form submit syntax

Postby Westy » Fri Sep 19, 2014 5:02 pm

Thank you very much.

Dean
Westy
 
Posts: 852
Joined: Fri Feb 13, 2004 5:27 am
Location: Lynnfield, Massachusetts USA


Return to Servoy Web Client

Who is online

Users browsing this forum: No registered users and 2 guests