0

Here is the code to Receive the POST :

{{velocity}}
#if ($request.getMethod() == "POST")
$request.getParameter("servicename")
#end
{{/velocity}}

Here is the code to Send the POST :

{{velocity}}

{{html}}

Here is the code for the javascript :

<script type="text/javascript">
function validateForm()
{

c = confirm("Are you sure ?");
if(c == true){
alert("The foo has been created");
}else{
alert("The foo creation has been canceled.");
return false;
}
}
</script>

Here is the code for the html form :

<form name="myForm" action="$doc.getURL('view')" method="post" onsubmit="return  validateForm()">
<input type="hidden" name="xaction" value="createservice" />
 Foo Name:
<input type="text" name="servicename" />
 <input type="submit" value="Create" />
 </form>
{{/html}}

 {{/velocity}}
Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • Sorry but what's your problem, here? What's the behavior when you run your code? – Rodolphe Nov 08 '11 at 13:46
  • What actually happens? It's also good to mention that you're working in the XWiki environment, and there's no JSP involved in what you're doing. – Dave Newton Nov 12 '11 at 20:24

1 Answers1

1

I don't know if this will help you but the following code works:

<html>
<head>
<script type="text/javascript">

function foo() {
    if (confirm("Are you sure?")) {
        alert("OK");
        return true;
    }
    else {
        alert("KO");
        return false;
    }
}

</script>
</head>
<body>

<form method="post" onsubmit="return foo()">
    <input type="text" />
    <input type="submit" value="Go" />
</form>

</body>
</html>

And then you can get rid of foo:

<form method="post" onsubmit="return confirm('Are you sure?')">
Rodolphe
  • 1,689
  • 1
  • 15
  • 32