Jump to content

Setting the value to a variable after the Submit button


cag17

Recommended Posts

I am trying to pass a variable to a mySQL database from a PHP fill-in-form page.  The field that I am trying to set isn't accessable from the person filing in the form.  This field is dependent on what is filled in on the form.  With that being said, what is the best way to handle this in code?  I am working with the onSubmit but I am not getting the results that I thought that I would get.  Is there a better way to handle this?

Link to comment
Share on other sites

Sound interesting. Can you tell us more.

 

Javascript would work but you'd still have to process which fields have been filled out with what in order to get the hidden result you want to post.

 

You could easily just fill in this variable on the page that processes the form.

 

ie check what values have been submitted, run some code to generate the variable based on those submitted fields, then process the form.

Link to comment
Share on other sites

The fill-in-form asks qustions about training and if they answer yes then I need to make the hidden field equal "yes" for being qualified.  This sounded easy until I got into it.

 

If I do this:

<form action="process.php" method="post">

<input type="textfield" name="field1" id="field1" />

<input type="submit" name="process" value="process" />

</form>

 

 

and send the form to "process.php", There I can set the variables needed.  If I do it this way will I need to also insert in the table in the "process.php"?  Is this the best way?

 

Link to comment
Share on other sites

Javascript is a bad solution for this - if a user has it turned off, your form falls apart.

 

Why don't you just use PHP to check the values after they have been submitted to process.php and then set your variable there?

Link to comment
Share on other sites

This isn't want I am using.  I just saw this and thought that it would work.

 

Here is the exact form that I am using:

 

<form action="<?php echo $editFormAction; ?>" method="POST" name="form1" id="form1" onSubmit="return setqual()">
              <label>
              <label>
              <div align="right">Date <?php $today = date('Y/m/d'); ?>
                <input name="date" type="text" id="date" accesskey="1" value=<?php echo $today; ?> size="12" readonly="true" />
                <br />
                <br />
              </div>
              </label>
              <div align="center">First Name
                <input name="fname" type="text" id="fname" tabindex="2" size="55" />
              </div>
              </label>
            
              <p align="center">
              <label>Last Name
              <input name="lname" type="text" id="lname" tabindex="3" size="55" />
              </label></p>
              <div align="center"></div>
              <table width="600" border="0">
                <tr>
                  <td height="56"><div align="center">Date of Birth:<br />
                  </div>
                    <label>
                    <div align="center">
                      <select name="month" id="month" tabindex="4">
                        <option value="0" selected="selected">Month</option>
                        <option value="January">January</option>
                        <option value="February">February</option>
                        <option value="March">March</option>
                        <option value="April">April</option>
                        <option value="May">May</option>
                        <option value="June">June</option>
                        <option value="July">July</option>
                        <option value="August">August</option>
                        <option value="September">September</option>
                        <option value="October">October</option>
                        <option value="November">November</option>
                        <option value="December">December</option>
                      </select>
                      <select name="day" id="day" tabindex="5">
                        <option value="0">Day</option>
                        <option value="1">1</option>
                        <option value="2">2</option>
                        <option value="3">3</option>
                        <option value="4">4</option>
                        <option value="5">5</option>
                        <option value="6">6</option>
                        <option value="7">7</option>
                        <option value="8">8</option>
                        <option value="9">9</option>
                        <option value="10">10</option>
                        <option value="11">11</option>
                        <option value="12">12</option>
                        <option value="13">13</option>
                        <option value="14">14</option>
                        <option value="15">15</option>
                        <option value="16">16</option>
                        <option value="17">17</option>
                        <option value="18">18</option>
                        <option value="19">19</option>
                        <option value="20">20</option>
                        <option value="21">21</option>
                        <option value="22">22</option>
                        <option value="23">23</option>
                        <option value="24">24</option>
                        <option value="25">25</option>
                        <option value="26">26</option>
                        <option value="27">27</option>
                        <option value="28">28</option>
                        <option value="29">29</option>
                        <option value="30">30</option>
                        <option value="31">31</option>
                      </select>
                    , 19
                    <select name="year" id="year" tabindex="6">
                      <option value="0">Year</option>
                      <option value="50">50</option>
                      <option value="51">51</option>
                      <option value="52">52</option>
                      <option value="53">53</option>
                      <option value="54">54</option>
                      <option value="55">55</option>
                      <option value="56">56</option>
                      <option value="57">57</option>
                      <option value="58">58</option>
                      <option value="59">59</option>
                      <option value="60">60</option>
                      <option value="61">61</option>
                      <option value="62">62</option>
                      <option value="63">63</option>
                      <option value="64">64</option>
                      <option value="65">65</option>
                      <option value="66">66</option>
                      <option value="67">67</option>
                      <option value="68">68</option>
                      <option value="69">69</option>
                      <option value="70">70</option>
                      <option value="71">71</option>
                      <option value="72">72</option>
                      <option value="73">73</option>
                      <option value="74">74</option>
                      <option value="75">75</option>
                      <option value="76">76</option>
                      <option value="77">77</option>
                      <option value="78">78</option>
                      <option value="79">79</option>
                      <option value="80">80</option>
                      <option value="81">81</option>
                      <option value="82">82</option>
                      <option value="83">83</option>
                      <option value="84">84</option>
                      <option value="85">85</option>
                      <option value="86">86</option>
                      <option value="87">87</option>
                      <option value="88">88</option>
                      <option value="89">89</option>
                      <option value="90">90</option>
                      <option value="91">91</option>
                      <option value="92">92</option>
                      <option value="93">93</option>
                      <option value="94">94</option>
                      <option value="95">95</option>
                    </select>
</div>
                    </label>
                    <label>
                    <div align="center"></div>
                    </label>
                    <label>
                    <div align="center"></div>
                    </label>                    <label></label></td>
                  </tr>
                <tr>
                  <td height="56"><div align="center">
                    <h3><br />
                      Driver's License Info</h3>
                  </div>
                    <label>
                    <div align="center">State
                      <input name="licstate" type="text" id="licstate" tabindex="7" size="3" />
                      Number
  <input name="licnum" type="text" id="licnum" tabindex="8" size="15" />
                    </div>
                    </label></td>
                  </tr>
              </table>
             
              <table width="412" border="0" align="center">
                <tr>
                  <td colspan="2" valign="top"> </td>
                  </tr>
                <tr>
                  <td width="51" valign="top">Address</td>
                  <td width="351"><input name="address1" type="text" id="address1" tabindex="9" size="55" />
                    <input name="address2" type="text" id="address2" tabindex="10" size="55" />
                    <br /></td>
                </tr>
                <tr>
                  <td><div align="right">City</div></td>
                  <td><label>
                    <input name="city" type="text" id="city" tabindex="12" size="55" />
                  </label></td>
                  </tr>
                <tr>
                  <td> </td>
                  <td><label>
St.
  <input name="state" type="text" id="state" tabindex="13" size="3" />
      Zip
  <input name="zip" type="text" id="zip" tabindex="14" size="8" />
              </table>
              <table width="584" border="0" align="center">
                <tr>
                  <td colspan="2"><h3 align="center"><br />
                    Contact Information</h3></td>
                  </tr>
                <tr>
                  <td width="260"><label>Home Number
                      <input type="text" name="hnum" id="hnum" tabindex="15" />
                  </label></td>
                  <td width="314"><label>Cell Number
                      <input type="text" name="cnum" id="cnum" tabindex="16" />
                  </label></td>
                </tr>
                <tr>
                  <td><label>
                    <div align="left">Other Number
                      <input type="text" name="othernum" id="othernum" tabindex="17" />
                    </div>
                  </label></td>
                  <td><label>Email
                    <input name="email" type="text" id="email" tabindex="18" size="40" />
                  </label></td>
                </tr>
              </table>
              <table width="585" border="0" align="center">
                <tr>
                  <td><div align="center">
                    <h3><br />
                      Education Information</h3>
                  </div></td>
                  </tr>
                <tr>
                  <td><label>What is the highest level of education the you have completed: 
                      <select name="level" id="level" tabindex="19">
                        <option value="0" selected="selected">Please Select</option>
                        <option value="no diploma">Some High School</option>
                        <option value="diploma">High School</option>
                        <option value="diploma plus">Some College</option>
                        <option value="associates">Associate</option>
                        <option value="bachelor">Bachelor</option>
                        <option value="master">Master</option>
                        <option value="doctor">Doctor</option>
                      </select>
                  </label>                    <label></label></td>
                  </tr>
                <tr>
                  <td><div align="center"><br />
                    Have you completed BLET 
                    <select name="compBLET" id="compBLET" tabindex="20">
                      <option value="no" selected="selected">No</option>
                      <option value="yes">Yes</option>
                      </select>
                      <br />
                    If yes, when
  <select name="compBLETsea" id="compBLETsea" tabindex="21">
    <option value="0" selected="selected"></option>
    <option value="spring">Spring</option>
    <option value="summer">Summer</option>
    <option value="fall">Fall</option>
    <option value="winter">Winter</option>
  </select>
                    of
  <select name="compBLETyear" id="compBLETyear" tabindex="22">
    <option value="0" selected="selected"></option>
    <option value="1990">1990</option>
    <option value="1991">1991</option>
    <option value="1992">1992</option>
    <option value="1993">1993</option>
    <option value="1994">1994</option>
    <option value="1995">1995</option>
    <option value="1996">1996</option>
    <option value="1997">1997</option>
    <option value="1998">1998</option>
    <option value="1999">1999</option>
    <option value="2000">2000</option>
    <option value="2001">2001</option>
    <option value="2002">2002</option>
    <option value="2003">2003</option>
    <option value="2004">2004</option>
    <option value="2005">2005</option>
    <option value="2006">2006</option>
    <option value="2007">2007</option>
    <option value="2008">2008</option>
    <option value="2009">2009</option>
    <option value="2010">2010</option>
    <option value="2011">2011</option>
    <option value="2012">2012</option>
    <option value="2013">2013</option>
    <option value="2014">2014</option>
    <option value="2015">2015</option>
  </select>
                  </div></td>
                  </tr>
                <tr>
                  <td><div align="center"></div>
                    <label>
                    <div align="center"><br />
                      Are you currently attending BLET
                      <select name="currBLET" id="currBLET" tabindex="22">
                        <option value="no" selected="selected">No</option>
                        <option value="yes">Yes</option>
                      </select>
                      <br />
                      If yes, completion date
                      <select name="currBLETsea" id="currBLETsea" tabindex="23">
                        <option value="0" selected="selected"></option>
                        <option value="spring">Spring</option>
                        <option value="summer">Summer</option>
                        <option value="fall">Fall</option>
                        <option value="winter">Winter</option>
                      </select>
                      of 
  <select name="currBLETyear" id="currBLETyear" tabindex="24">
    <option value="0" selected="selected"></option>
    <option value="2008">2008</option>
    <option value="2009">2009</option>
    <option value="2010">2010</option>
    <option value="2011">2011</option>
    <option value="2012">2012</option>
    <option value="2013">2013</option>
    <option value="2014">2014</option>
    <option value="2015">2015</option>
    <option value="2016">2016</option>
    <option value="2017">2017</option>
    <option value="2018">2018</option>
    <option value="2019">2019</option>
    <option value="2020">2020</option>
  </select>
                    </div>
                    </label></td>
                  </tr>
                <tr>
                  <td height="97"><div align="center"><br />
                  </div>
                    <label>
                    <div align="center">Are you Currently a NC Certified officer?
                      <select name="officer" id="officer" tabindex="25">
                        <option value="no" selected="selected">No</option>
                        <option value="yes">Yes</option>
                        </select>
                    </div>
                    </label>
                    <div align="center"></div>
                    <label>
                    <div align="center">If yes, Agency Name
                      <input name="agencyname" type="text" id="agencyname" tabindex="26" size="55" />
                    </div>
                    </label>
                    <div align="center"></div>
                    <label>
                    <div align="center">Date of employment?

                      <select name="empmonth" id="empmonth" tabindex="23">
                                          <option value="0" selected="selected">Month</option>
                                          <option value="January">January</option>
                                          <option value="February">February</option>
                                          <option value="March">March</option>
                                          <option value="April">April</option>
                                          <option value="May">May</option>
                                          <option value="June">June</option>
                                          <option value="July">July</option>
                                          <option value="August">August</option>
                                          <option value="September">September</option>
                                          <option value="October">October</option>
                                          <option value="November">November</option>
                                          <option value="December">December</option>
                      </select>
                    , 
                    <select name="empyear" id="empyear" tabindex="28">
                      <option value="0" selected="selected">Year</option>
                      <option value="1980">1980</option>
                      <option value="1981">1981</option>
                      <option value="1982">1982</option>
                      <option value="1983">1983</option>
                      <option value="1984">1984</option>
                      <option value="1985">1985</option>
                      <option value="1986">1986</option>
                      <option value="1987">1987</option>
                      <option value="1988">1988</option>
                      <option value="1989">1989</option>
                      <option value="1990">1990</option>
                      <option value="1991">1991</option>
                      <option value="1992">1992</option>
                      <option value="1993">1993</option>
                      <option value="1994">1994</option>
                      <option value="1995">1995</option>
                      <option value="1996">1996</option>
                      <option value="1997">1997</option>
                      <option value="1998">1998</option>
                      <option value="1999">1999</option>
                      <option value="2000">2000</option>
                      <option value="2001">2001</option>
                      <option value="2002">2002</option>
                      <option value="2003">2003</option>
                      <option value="2004">2004</option>
                      <option value="2005">2005</option>
                      <option value="2006">2006</option>
                      <option value="2007">2007</option>
                      <option value="2008">2008</option>
                      <option value="2009">2009</option>
                      <option value="2010">2010</option>
                      <option value="2011">2011</option>
                      <option value="2012">2012</option>
                      <option value="2013">2013</option>
                      <option value="2014">2014</option>
                      <option value="2015">2015</option>
                    </select>
</div>
                    </label>
<label></label>
<label>
<div align="center"></div>
</label>
<label>
<div align="center"></div>
</label></td>
                  </tr>
              </table>
              <table width="600" border="0">
                <tr>
                  <td height="45"><label> 
                    <div align="right"><br />
                        <input type="submit" name="Send" id="Send" value="Submit" tabindex="30" />                      
                      
                    </div>
                  </label></td>
                  <td> </td>
                  <td><label>
                    <br />
                    <input type="reset" name="clear" id="clear" value="Reset" tabindex="31" />
                  </label></td>
                </tr>
              </table>
              <p><br />  
                  <label></label>
              </p>
              <p> </p>
              
              
              
              <input type="hidden" name="MM_insert" value="form1" />
            </form>

 

when the submit is clicked , I need the qualified field to be added as well and that is conditional on the answers to the compBLET, currBLET, and officer menu items inside of the form.

Link to comment
Share on other sites

Sorry for the confusion on this.  If I do it this way then yes, I would handle the yes or know for the qualified field and then, I think that I would have to handle the insert for the rest of the fill-in-form.

 

Is this the best way to handle it or will it even work like this?

Link to comment
Share on other sites

What?

 

If I do it this way

 

What is 'this way'? The way I suggested?

 

then yes, I would handle the yes or know for the qualified field and then, I think that I would have to handle the insert for the rest of the fill-in-form.

 

I'm sorry, I really have no idea what you just said.

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.