Jump to content

Add state list and toggle fields to email form


PerF

Recommended Posts

I am having trouble adding a state list and toggle fields to my email form.

Please help.

I need a dropdown of states for the field US States 

I need a toggle with three choices for field Condition below the field

I need a toggle with 4 choices for field Title below the field

 

Here is a link to a picture of what I want to achieve.

www.macroarts.com/filedemo/formimage.html

 

Here is the code.  All other fields work. No problem.

<body bgcolor="#000000" text="#FFFFFF">
    
    <form name="contactformfree" method="post" action="free_process.php" onsubmit="return validate.check(this)">
    <table width="100px" class="cffree">
    <tr>
     <td colspan="2">
      <p style="text-align:center">Fields marked with <span class="required_star"> * </span> are required.</p>
     </td>
    </tr>
    <tr>
     <td valign="top" class="cffree_td">
      <label for="First_Name" class="required">First Name<span class="required_star"> * </span></label>
     </td>
     <td valign="top" class="cffree_td">
      <input type="text" name="First_Name" id="First_Name" maxlength="80" style="width:50px">
     </td>
    
     <td valign="top" class="cffree_td">
      <label for="Last_Name" class="required">Last Name<span class="required_star"> * </span></label>
     </td>
     <td valign="top" class="cffree_td">
      <input type="text" name="Last_Name" id="Last_Name" maxlength="80" style="width:50px">
     </td>
    </tr>
    <tr>
     <td valign="top" class="cffree_td">
      <label for="Email_Address" class="required">Email<span class="required_star"> * </span></label>
     </td>
     <td valign="top" class="cffree_td">
      <input type="text" name="Email_Address" id="Email_Address" maxlength="100" style="width:50px">
     </td>
    
     <td valign="top" class="cffree_td">
      <label for="Telephone_Number" class="required">Phone<span class="required_star"> * </span></label>      
     </td>
     <td valign="top" class="cffree_td">
      <input type="text" name="Telephone_Number" id="Telephone_Number" maxlength="100" style="width:50px">
     </td>
    </tr>
    <tr>
     <td valign="top" class="cffree_td">
      <label for="City" class="not-required">City</label>
     </td>
     <td valign="top" class="cffree_td">
      <input type="text" name="City" id="City" maxlength="100" style="width:22px">
     </td>
    
     <td valign="top" class="cffree_td">
      <label for="US_States" class="not-required">US States</label>
     </td>
     <td valign="top" class="cffree_td">
      <input type="text" name="US_States" id="US_States" maxlength="100" style="width:22px">
     </td>

    
     <td valign="top" class="cffree_td">
      <label for="Zip" class="not-required">Zip</label>
     </td>
     <td valign="top" class="cffree_td">
      <input type="text" name="Zip" id="Zip" maxlength="100" style="width:28px">
     </td>
    </tr>
    <tr>
     <td valign="top" class="cffree_td">
      <label for="Year" class="required">Year<span class="required_star"> * </span></label>      
     </td>
     <td valign="top" class="cffree_td">
      <input type="text" name="Year" id="Year" maxlength="100" style="width:33px">
     </td>
    
     <td valign="top" class="cffree_td">
      <label for="Make" class="required">Make<span class="required_star"> * </span></label>      
     </td>
     <td valign="top" class="cffree_td">
      <input type="text" name="Make" id="Make" maxlength="100" style="width:33px">
     </td>
     
          <td valign="top" class="cffree_td">
      <label for="Model" class="required">Model<span class="required_star"> * </span></label>      
     </td>
     <td valign="top" class="cffree_td">
      <input type="text" name="Model" id="Model" maxlength="100" style="width:33px">
     </td>
     
    </tr>
    <tr>
     <td valign="top" class="cffree_td">
      <label for="Millage" class="not-required">Millage</label>
     </td>
     <td valign="top" class="cffree_td">
      <input type="text" name="Millage" id="Millage" maxlength="100" style="width:24px">
     </td>

     <td valign="top" class="cffree_td">
      <label for="Condition" class="not-required">Condition</label>
     </td>
     <td valign="top" class="cffree_td">
      <input type="text" name="Condition" id="Condition" maxlength="100" style="width:31px">
     </td>

     <td valign="top" class="cffree_td">
      <label for="Title" class="not-required">Title</label>
     </td>
     <td valign="top" class="cffree_td">
      <input type="text" name="Title" id="Title" maxlength="100" style="width:20px">
     </td>

    </tr>
    <tr>
     <td valign="top" class="cffree_td">
            <label for="Additional_Information" class="not-required">Additional Information</label>
     </td>
     <td valign="top" class="cffree_td">
      <textarea style="width:250px;height:120px" name="Additional_Information" id="Additional_Information" maxlength="2000" style="width:50px" ></textarea>
     </td>
    </tr>
    <tr>
     <td colspan="2" style="text-align:center"  class="cffree_td">
      <input type="submit" value=" Submit Form ">
      <br /><br />

      <br /><br />
     </td>
    </tr>
    </table>
    </form>

 

 

Link to comment
Share on other sites

Since you haven't done anything here's a little something that was easy to produce:

//  Open a text file of state names
//  format of file is simply a state name on each line.
$input_name = 'pathtotextfileofstates';
if(!$states_file = fopen($input_name, 'r'))
{
	echo "Could not open input states file '$input_name'<br>";
	exit();
}
//  read in the state names
$arr = array();	// array to save names in for sorting and processing
while($line = fgets($states_file,30))
{
	$arr[] = $line;
}
// put names into alphabetical order
sort($arr);		
//   create the output name
$output_name = 'pathtooutputhtmlfile';
if (!$out_hdl = fopen($output_name, 'c'))
{
	echo "Could not open output file '$output_name'<br>";
	exit();
}
//  start creating option tags and the html file that you will use
//  in your mail form script
$out_cnt = 0;
foreach($arr as $st)
{
	// create the option tag for the dropdown list to use
	$output_tag = "<option value='$st'>$st</option>";
	$result = fwrite($out_hdl, $output_tag);
	if (!$result)
	{
		echo "Error writing state '$output_tag'<br>";
		exit();
	}
	else
	{
		$out_cnt++;
		echo "Wrote $output_tag<br>";
	}
}
fclose($out_hdl);
echo "Wrote out $out_cnt option tags<br>";
//  include this file in the html inside of the <select> start and end tags
//  Obviously you only need to run this once.
exit(); 

The idea is to produce the <option> tags for the states and save them in a plain text file.  You will then include that in your script where you have the dropdown list.  It is already in html so you just simply do the include in a block of php code:

echo "<select name='state_dropdown'>";
require 'pathtostatesfile';
echo "</select">;
(continue on with html)

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.