Can a form be written in this way
Posted: Thu Feb 22, 2007 10:55 pm
Don't know which is right place for this post.
I've use case where I should not use make more than one php file. I've to make add,edit,delete along with paginantion.
I've made a one single form in which seperate form fields for edit, sepearate form fields for addition. and two similar buttons for calling same javascript source file using same javasctript function, Two submit buttons. The add and edit are seperated with if logic, so there is no harm from my side as I thought.
what will be the pros and cons of using such forms.
Im pasting here a sample code of that
I've use case where I should not use make more than one php file. I've to make add,edit,delete along with paginantion.
I've made a one single form in which seperate form fields for edit, sepearate form fields for addition. and two similar buttons for calling same javascript source file using same javasctript function, Two submit buttons. The add and edit are seperated with if logic, so there is no harm from my side as I thought.
what will be the pros and cons of using such forms.
Im pasting here a sample code of that
Code: Select all
<form>
<?php
if($action=='edit'){
echo "<input type=hidden name=id[0] value='$ID'>".
"<table align=left width='90%' cellspacing='0' cellpadding='0' border='1'><tr><td><b>Edit</b></td></tr>\r\n". "<tr><td><h3>Name</h3></td> <td><input type=hidden name=action value='edit'><input type=text name=name value=".$result_obj->name."></td></tr>". "<tr><td><h3>Periodcity</h3></td> <td><select name=period>".periodicity($result_obj->period)."</select></td></tr>". "<tr><td><h3>Category</h3></td><td><select name=cat_ID>".$cats."</select></td></tr>". "<tr><td><h3>Location</h3></td><td><input type=text name='location' value='".htmlentities($location)."'></td><td align=left valign='top'><p class='submit'><input type='button' value='Show' onclick=testDef(location.value)></p><strong>Search Results=</strong><div id='es'></div><strong> Details</strong><div id='asa'></div></td></tr>"."<tr><td><h3>Url</h3></td><td><input type=text name=source size=65 value=".$result_obj->source."></td></tr>"."<tr><td> </td><td align=right><p class='submit'><input type='submit' name='add' value='Save' /></p></td></tr>"."</table>";
}else{
echo "<input type=hidden name=d[0] value='0'>".
"<table align=left width='90%' cellspacing='0' cellpadding='0' border='1'><tr><td><b>Add New</b></td></tr>\r\n". "<tr><td><h3>Name</h3></td> <td><imput type=hidden name=action value='add'><input type=text name=name value=''></td></tr>".
"<tr><td><h3>Periodcity</h3></td> <td><select name=period>".periodicity()."</select></td></tr>".
"<tr><td><h3>Category</h3></td><td><select name=cat_ID[0] >".$cats."</select></td></tr>".
"<tr><td><h3>Location</h3></td><td><input type=text name='location' value=''></td><td align=left valign='top'><p class='submit'><input type='button' value='Show' onclick=testDef(location.value)></p><strong>Search Results=</strong><div id='es'></div><strong>Details</strong><div id='asa'></div></td></tr>". "<tr><td><h3> Url</h3></td><td><input type=text name=source[0] size=65 value='""'></td></tr>"."<tr><td> </td><td align=right><p class='submit'><input type='submit' name='add' value='Save' /></p></td></tr>"."</table>";
}?>
</form>