Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make the code correct on on Perl

Status
Not open for further replies.

jem12

Technical User
Jul 2, 2010
1
SE
Hello

I have PHP file that contain HTML form.
Every thing is ok on it, but the problem is when I want make checkbox.

There is 8 checkbox and man can only choose 3 of them and then be sent with whole information by e-mail.

Question 1:
Well, I send you code and I hope you can remove the Javascript code and write instead on Perl.

Question 2:
How can I show with checkbox is on?

Here is the code include example that will show result:



<?php
?>
<html>
<script type="text/javascript">
function check(){
kott=document.forms[0].kott
a=0
for (i=0;i<8;++ i)
{
if (kott.checked)
{
a=a+1
}
}
if (a > 3)
{
alert("You did choose more than 3 of 8.\nYou have to choose only 3.")
}
}
</script>

<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<table width="600"><tr>

<div align="left">
<input type="checkbox" name="kott" value="0" alt="Rostbiff" onClick="check()">Rostbiff</div>
<div>
<input type="checkbox" name="kott" value="1" alt="Fläskfilé" onClick="check()">Fläskfilé</div>
<div>
<input type="checkbox" name="kott" value="2" alt="Kycklingfilé;" onClick="check()">Kycklingfilé;</div>
<div>
<input type="checkbox" name="kott" value="3" alt"Kycklingklubbor" onClick="check()">Kycklingklubbor</div>
<div>
<input type="checkbox" name="kott" value="4" alt="Kalkonfilé" onClick="check()">Kalkonfil&eacute;</div>
<div>
<input type="checkbox" name="kott" value="5" alt"Rökt skinka" onClick="check()">Rökt skinka</div>
<div>
<input type="checkbox" name="kott" value="6" alt"Gourmet Skinka" onClick="check()">Gourmet Skinka</div>
<div>
<input type="checkbox" name="kott" value="7" alt"Kassler" onClick="check()">Kassler</div>
</tr>
<td>
<div align="center">
<input type="reset" name="reset" value="Rest">
&nbsp;&nbsp;
<input type="submit" name="submit" value="Print down the checkbox that is ON" >
</div></td></table></form>
<br>
Example printing will show result that is on: <br>
You did choose the following: <strong>Rostbiff , Rökt skinka and Gourmet Skinka</strong>
</body>
</html>

<?php
?>
 
Why is the form multipart?
You can't do user-side form checking without javascript.
You can do server-side checking with perl.
This is an extremely simple perl script if you just want to make the forms page in html.
Acting on the form to send the data by email is more complicated, but free scripts are available on the web all over, unless there is already a script doing this, then just use that forms address for form action.

Try view source to see it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top