PHP Form help
-
Hi, I have a form that I am creating for my website, and its for people to use if they find a butterfly or moth and cannot identify it. Basically what I want is for the user to fill in the form and if they have an image to send, select an image and send the message. Code I have:
<form action="mailer.php" method="post" name="form1" id="form1" style="margin:0px; font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px; width:300px;" onsubmit="MM_validateForm('from','','RisEmail','subject','','R','verif_box','','R','message','','R');return document.MM_returnValue"> Your Name:<br /> <input name="name" type="text" id="name" style="padding:2px; border:1px solid #CCCCCC; width:180px; height:14px; font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px;" value="<?php echo $_GET['name'];?>"/> <br /> <br /> Your e-mail:<br /> <input name="from" type="text" id="from" style="padding:2px; border:1px solid #CCCCCC; width:180px; height:14px; font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px;" value="<?php echo $_GET['from'];?>"/> <br /> <br /> Stage:<br /> <select name="stage"> <option value="Caterpillar">Caterpillar</option> <option value="Pupa">Pupa</option> <option value="Cocoon">Cocoon</option> <option value="Adult">Cocoon</option> <option value="Leaf Mine">Leaf Mine</option> <option value="Leaf Mine Vaccated">Leaf Mine (Vaccated)</option> </select><br /> <br /> Method:<br /> <select name="method"> <option value="UV Light Trap">UV Light Trap</option> <option value="MV Lamp">Mercury Vapour Lamp</option> <option value="Tungsten Light">Tungsten Light</option> <option value="Actinic Light">Actinic light</option> <option value="Household Bulb">Household Bulb</option> <option value="Camping Lamp">Camping Lamp</option> <option value="Infrared">Infrared Light</option> <option value="LED Lights">LED Lights</option> <option value="Carlights">Car Headlights</option> <option value="Lighted Window">Attracted to Lighted Window</option> <option value="Streetlight">At street light</option> <option value="Security light">At security light</option> <option value="Torch">Found via torchlight</option> <option val
-
Hi, I have a form that I am creating for my website, and its for people to use if they find a butterfly or moth and cannot identify it. Basically what I want is for the user to fill in the form and if they have an image to send, select an image and send the message. Code I have:
<form action="mailer.php" method="post" name="form1" id="form1" style="margin:0px; font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px; width:300px;" onsubmit="MM_validateForm('from','','RisEmail','subject','','R','verif_box','','R','message','','R');return document.MM_returnValue"> Your Name:<br /> <input name="name" type="text" id="name" style="padding:2px; border:1px solid #CCCCCC; width:180px; height:14px; font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px;" value="<?php echo $_GET['name'];?>"/> <br /> <br /> Your e-mail:<br /> <input name="from" type="text" id="from" style="padding:2px; border:1px solid #CCCCCC; width:180px; height:14px; font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px;" value="<?php echo $_GET['from'];?>"/> <br /> <br /> Stage:<br /> <select name="stage"> <option value="Caterpillar">Caterpillar</option> <option value="Pupa">Pupa</option> <option value="Cocoon">Cocoon</option> <option value="Adult">Cocoon</option> <option value="Leaf Mine">Leaf Mine</option> <option value="Leaf Mine Vaccated">Leaf Mine (Vaccated)</option> </select><br /> <br /> Method:<br /> <select name="method"> <option value="UV Light Trap">UV Light Trap</option> <option value="MV Lamp">Mercury Vapour Lamp</option> <option value="Tungsten Light">Tungsten Light</option> <option value="Actinic Light">Actinic light</option> <option value="Household Bulb">Household Bulb</option> <option value="Camping Lamp">Camping Lamp</option> <option value="Infrared">Infrared Light</option> <option value="LED Lights">LED Lights</option> <option value="Carlights">Car Headlights</option> <option value="Lighted Window">Attracted to Lighted Window</option> <option value="Streetlight">At street light</option> <option value="Security light">At security light</option> <option value="Torch">Found via torchlight</option> <option val
Briefly, you will need to add a scrap of javascript to your page. In your
<form ... >
add something likeonsubmit="return check_fields()"
Somewhere in your page (I put it in thehead
section) put something like<script type="text/javascript">
function check_fields() {
if (document.getElementById("xxx").checked || document.getElementById("yyy").checked)
return true;
alert("You must select either xxx or yyy!");
return false;
}
</script>The function should return
true
if it's OK to submit. If there's something wrong, spit out an alert to say what the problem is, and return false so the form won't actually be submitted. Obviously, your checking will be more complex than this example which I ripped out of one of my sites. Cheers, Peter If this answers your question, vote for it.Software rusts. Simon Stephenson, ca 1994.
-
Briefly, you will need to add a scrap of javascript to your page. In your
<form ... >
add something likeonsubmit="return check_fields()"
Somewhere in your page (I put it in thehead
section) put something like<script type="text/javascript">
function check_fields() {
if (document.getElementById("xxx").checked || document.getElementById("yyy").checked)
return true;
alert("You must select either xxx or yyy!");
return false;
}
</script>The function should return
true
if it's OK to submit. If there's something wrong, spit out an alert to say what the problem is, and return false so the form won't actually be submitted. Obviously, your checking will be more complex than this example which I ripped out of one of my sites. Cheers, Peter If this answers your question, vote for it.Software rusts. Simon Stephenson, ca 1994.
Thanks Peter, will try that.
In the end we're all just the same