1 Reply Latest reply on Apr 19, 2010 12:37 PM by dan hop

    Combining form INPUT fields

    dan hop

      I had a problem combining form INPUT fields on my PHP web page.

      Tried doing it in formMailer using PHP... didn't work.

      Several folks here tried to help-couldn't find an easy solution.

      Posts all over the net seemed to beg the problem without a simple solution.

       

      Ran across some code that suggested that JavaScript might be the answer but that passing the value of the combined INPUT fields might be a problem.

       

      Here's the solution I came up with.

      It works. It's simple. Here goes:

      ...................................

      ...
      <HTML>
      <HEAD>
      ...
      <SCRIPT type="text/javascript">
      function ValidateForm(true_false)
      {   
      if (document.form_name.first_name.value== "")
          {alert("You forgot to enter your name. \n Please do so now.");
          document.form_name.first_name.focus();
          return false;}
      else if (document.form_name.last_name.value== "")
          {alert("Please enter your email address so we can reply to your note.");
          document.form_name.last_name.focus();
          return false;}
      ...
      else if (document.form_name.captcha_entry.value== "")
          {alert("You must enter the answer to the security question \n so we can get your comments.");
          document.form_name.captcha_entry.focus();
          return false;}   
      else
          document.form_name.cName.value=(document.form_name.first_name.value)+' '+(document.form_name.last_name.value);
          {return true;}
      }
      </SCRIPT>
      </HEAD>
      <BODY>
      ...
      <FORM  method="post" name="form_name" id="form_name" action="formmail.php" onSubmit="return ValidateForm(this)">
      ...
      <INPUT name="first_name" type="text">
      <INPUT name="last_name" type="text">
      <INPUT name="cName" type="text" class="hidden_field">
      ...
      </FORM>
      </BODY>
      </HTML>
      .........................................

      Any comments/suggestions?

       

      Dan H.

        • 1. Re: Combining form INPUT fields
          dan hop Level 1

          I should have added:

          The FormMailer script asks for the first name, last name, email address of the sender.

          It also asks for the name of the submitter that will be included in the 'From' part of the resulting email.

          That name is now 'cName' (first_name, space, last_name)

           

          Dan H.