ilterocktivity
07-14-2006, 01:22 PM
Hello dear coders. I bow down before you :)
(I roughly made a search in the forum, but couldn't find the answer. So if it was asked before, please help me find the thread. Im and old guy :p )
I have a form (oh how nice), which I used a generator, to create.
So, I don't know too much about html and php coding. Im a good tweaker, thats all.
I have a dropdown menu (which is a required field), and 4 options in it. But because the 1st option is default(ly appears), user is able to skip the dropdown without consciously choosing an option.
I want to force them to choose an option. Not the 1st option which appears.
I tried to put additional option, which will not exist in php process file, but I was not successfull. Here's the stripped down codes, that I have:
HTML form file:
<HTML><HEAD><TITLE>My Form</TITLE></HEAD>
<BODY>
<b>All fields marked with a * are required:</b><br>
<form enctype='multipart/form-data' action='process.php' method='post'>
<table width='50%' border=0>
<input type=text name='UserChoice'></td></tr>
<tr><td>Your Choice<font color='#ff0000'>*</font></td>
<td>
<select name='UserChoice'>
<option value='A1'>A1</option>
<option value='B2'>B2</option>
<option value='C3'>C3</option>
<option value='D4'>D4</option>
</select></td></tr>
</table>
<input type='submit' value='Submit Form'>
</form>
</BODY></HTML>
and this is my PHP process file (process.php)
<?php
include("global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
pt_register('POST','UserChoice');
if($UserChoice=="" ){
$errors=1;
$error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
}
if($errors==1) echo $error;
else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="Your Choice ".$UserChoice."
";
$message = stripslashes($message);
mail("my@mail.com","Form Submitted at your website",$message,"From: Generator");
$link = mysql_connect("localhost","user","password");
mysql_select_db("databaseName",$link);
$query="insert into tableName
(Your Choice) values
('".$UserChoice."'
)";
mysql_query($query);
$make=fopen("admin/data.dat","a");
$to_put="";
$to_put .= $UserChoice."
";
fwrite($make,$to_put);
?>
<!-- Content of the Thank you page -->
<h2>Thank you!</h2>
<table width=50%>
<tr><td>Your Choice </td><td> <?php echo $UserChoice; ?> </td></tr>
</table>
<?php
}
?>
You got what it is, but little bit more info:
process file is able to report, if a required field left empty. And reports it before it posts the form to MySQL database.
How to solve my problem, dear masters?
Thank you in advance.
PS. If I'm not clear enough, please let me know.
(I roughly made a search in the forum, but couldn't find the answer. So if it was asked before, please help me find the thread. Im and old guy :p )
I have a form (oh how nice), which I used a generator, to create.
So, I don't know too much about html and php coding. Im a good tweaker, thats all.
I have a dropdown menu (which is a required field), and 4 options in it. But because the 1st option is default(ly appears), user is able to skip the dropdown without consciously choosing an option.
I want to force them to choose an option. Not the 1st option which appears.
I tried to put additional option, which will not exist in php process file, but I was not successfull. Here's the stripped down codes, that I have:
HTML form file:
<HTML><HEAD><TITLE>My Form</TITLE></HEAD>
<BODY>
<b>All fields marked with a * are required:</b><br>
<form enctype='multipart/form-data' action='process.php' method='post'>
<table width='50%' border=0>
<input type=text name='UserChoice'></td></tr>
<tr><td>Your Choice<font color='#ff0000'>*</font></td>
<td>
<select name='UserChoice'>
<option value='A1'>A1</option>
<option value='B2'>B2</option>
<option value='C3'>C3</option>
<option value='D4'>D4</option>
</select></td></tr>
</table>
<input type='submit' value='Submit Form'>
</form>
</BODY></HTML>
and this is my PHP process file (process.php)
<?php
include("global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
pt_register('POST','UserChoice');
if($UserChoice=="" ){
$errors=1;
$error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
}
if($errors==1) echo $error;
else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="Your Choice ".$UserChoice."
";
$message = stripslashes($message);
mail("my@mail.com","Form Submitted at your website",$message,"From: Generator");
$link = mysql_connect("localhost","user","password");
mysql_select_db("databaseName",$link);
$query="insert into tableName
(Your Choice) values
('".$UserChoice."'
)";
mysql_query($query);
$make=fopen("admin/data.dat","a");
$to_put="";
$to_put .= $UserChoice."
";
fwrite($make,$to_put);
?>
<!-- Content of the Thank you page -->
<h2>Thank you!</h2>
<table width=50%>
<tr><td>Your Choice </td><td> <?php echo $UserChoice; ?> </td></tr>
</table>
<?php
}
?>
You got what it is, but little bit more info:
process file is able to report, if a required field left empty. And reports it before it posts the form to MySQL database.
How to solve my problem, dear masters?
Thank you in advance.
PS. If I'm not clear enough, please let me know.