E-MAIL: " TYPE="text"> DOCUMENT TITLE: *required " TYPE="text"> COMMENTS: --> Post edited by: kade119, at: 2008/01/31 22:01Post edited by: kade119, at: 2008/01/31 22:03"> Validating my form the proper way??? - Forums

Forums

Validating my form the proper way???

kade119 01 Feb, 2008
could someone step me thru this

i just need to validate one field, and make sure they input a title

do i put my html separate from my js, or all in teh same code box??


using this js

function validate_form ( )
{
    valid = true;

    if ( document.contact_form.recommendation.value == "" )
    {
        alert ( "Please fill in the 'Document Title' box." );
        valid = false;
    }

    return valid;
}


<form name="contact_form" method="post"
action="/cgi-bin/articles/development/
  javascript/form-validation-with-javascript/contact_simple.cgi"
onsubmit="return validate_form ( );">
              <table cellspacing="0" cellpadding="0" style="margin-bottom: -10px;">
                <tr>
                  <td><p>NAME:<span class="loud"></span> <br />
                      <INPUT NAME="name" value="<?=$name?>" TYPE="text">
                    </p></td>
                </tr>
                <tr>
                  <td><!--  -->
                    <p>E-MAIL:<span class="loud"> </span><br />
                      <INPUT NAME="email" value="<?=$email?>" TYPE="text">
                    </p></td>
             	</tr>
				 <tr>
                  <td><!--  -->
                    <p>DOCUMENT TITLE:<span class="loud"> *required</span><br />
                      <INPUT NAME="recommendation" value="<?=$document?>" TYPE="text">
                    </p></td>
             	</tr>
                <tr>
                  <td><p>COMMENTS:<br />
                      <textarea name="comments" class="cmsg" wrap="on"><?=$comments?></textarea>
                      <!--<br /> -->
                    </p></td>
                </tr>


</div>
                <tr>
                  <td><p style="margin-top: -3px;">
                      <INPUT TYPE="submit" CLASS="submit" VALUE=" Submit ">
                      <!--    -->
                      <INPUT TYPE="reset"CLASS="submit" VALUE=" Clear  ">
                  </td>
                </tr>
                <tr>
                 
                    </p>
                  </td>
                </tr>

</tr>
	</td>
              </table>
            </FORM>
          </div>


Post edited by: kade119, at: 2008/01/31 22:01<br><br>Post edited by: kade119, at: 2008/01/31 22:03
GreyHead 01 Feb, 2008
Hi kade119,

If you are using ChronoForms then put your Javascript in the Javascript box on the Form Code tab and put the Form HTML in the HTML code box - without the <form> tags. You'll need to make sure the form name matches the ChronoForms name too - I think you'll find this written up in the FAQs.

The values you have here won't work; they need to be of the form $_POST['email'] to preserve posted values or $my->name if you are looking for Joomla user values.

Bob
This topic is locked and no more replies can be posted.