PerF Posted December 3, 2021 Share Posted December 3, 2021 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> Quote Link to comment https://forums.phpfreaks.com/topic/314268-add-state-list-and-toggle-fields-to-email-form/ Share on other sites More sharing options...
ginerjm Posted December 3, 2021 Share Posted December 3, 2021 A select tag for the us states - that's easy. What's the hangup? What is a "toggle" to you? Not a term I use. Quote Link to comment https://forums.phpfreaks.com/topic/314268-add-state-list-and-toggle-fields-to-email-form/#findComment-1592394 Share on other sites More sharing options...
ginerjm Posted December 3, 2021 Share Posted December 3, 2021 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) Quote Link to comment https://forums.phpfreaks.com/topic/314268-add-state-list-and-toggle-fields-to-email-form/#findComment-1592400 Share on other sites More sharing options...
ginerjm Posted December 3, 2021 Share Posted December 3, 2021 Change 1 line in the above $arr[] = $line; S/B $arr[] = trim($line); Quote Link to comment https://forums.phpfreaks.com/topic/314268-add-state-list-and-toggle-fields-to-email-form/#findComment-1592401 Share on other sites More sharing options...
benanamen Posted December 3, 2021 Share Posted December 3, 2021 Just an FYI, Tables for layout went out in the 90's, We use CSS now. Quote Link to comment https://forums.phpfreaks.com/topic/314268-add-state-list-and-toggle-fields-to-email-form/#findComment-1592402 Share on other sites More sharing options...
ginerjm Posted December 3, 2021 Share Posted December 3, 2021 Looks like something he/she copied. Oh, well.... Quote Link to comment https://forums.phpfreaks.com/topic/314268-add-state-list-and-toggle-fields-to-email-form/#findComment-1592403 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.