Tuesday, May 15, 2012

Smarty php add multiple forms into single page and submit via javascript

Smarty is a web template system. It facilitates a manageable way to separate application logic and content from its presentation. Few times ago i have work with smarty web application. When i work on this i face few problem. One of the major one is when i try to add multiple HTML forms into same web page and then submit on one form, other form also try to submit. i think there are few possible way to slove above problem. i just go though the following way.

multipleforms.html


<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>External Seller | Control Panel</title>
</head>
<script language="JavaScript" type="text/javascript">
{literal}
function submitform(){
   document.form1.submit();
}

function submitform2(){
   document.form2.submit();
}
{/literal}
</script>
<body>
<form action="form1.php" name ="form1" id="form1" method="post">
    <input name="txt1" type="text"  id="txt1" value="{$server_obj->getValue()}"  size="50" />
    <input type="button" onclick="javascript: submitform()" id="submit1" value="Update First" class="button" />
</form>

    <br>
   
<form action="form2.php" name ="form2" id="form2" method="post">
    <input name="txt2" type="text"  id="txt2" value="{$server_obj2->getValue2()}"  size="50" />
    <input type="button" onclick="javascript: submitform2()" id="submit2" value="Update Second" class="button" />
</form>      
</body>
</html>

In the above example, i have use normal button instead of using submit button. On the button onclick event i have call JavaScript and submit form via that JavaScript. very Simple ;)

No comments:

Post a Comment