SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Apr 2002
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem with validation

    I want to make sure a value has been entered in my news form before it's submitted so that you can't submit a blank news entry.

    I know my functions work because the work in another form in the site but they won't quite work for this one.

    here's the FORM
    PHP Code:
    FORM NAME="news" ID="news" ACTION="<?php echo($PHP_SELF); ?>" onsubmit="return validateNewsForm(this)" METHOD=POST>
                              <TR><TD colspan = "2"><HR><P ALIGN='CENTER'>
                              News Heading:<BR>
                              <INPUT TYPE="TEXT" NAME="Heading" SIZE="32">
                              <INPUT TYPE="HIDDEN" NAME="AUTHOR" VALUE="<?php echo($uname); ?>">
                              </P></TD></TR><TR><TD colspan = "2"><P ALIGN='CENTER'>
                              Type your news here:<BR>
                              <TEXTAREA NAME="NEWS" ROWS=8 COLS=50 WRAP></TEXTAREA>
                              <INPUT TYPE="HIDDEN" NAME="page" VALUE="news">
                              <BR>
                              <INPUT TYPE="SUBMIT" NAME="ADD_NEWS" VALUE="Submit">
                              </P></TD></TR>
                              </FORM>
    and here's the script
    //----------------------------------------------
    function validRequired(formField,fieldLabel)
    {
    var result = true;

    if (formField.value.length == 0)
    {
    alert('Please enter a value for the "' + fieldLabel + '" field.');
    formField.focus();
    result = false;
    }
    }
    //--------------------------------------->
    function validateNewsForm(theForm)
    {
    if (!validRequired(theForm.Heading,"News Heading"))
    return false;

    if (!validRequired(theForm.NEWS,"News"))
    return false;

    return true;
    }
    //-------------------------------------------

    Here's what happends. If you leave the Heading blank and submit, it pops the message, if you enter something in the heading and the body is blank it won't do anything. If you type something in the body it still won't submit. Anyone see anything here I don't?

    Thanx

  2. #2
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wrong approach.

    Definately the wrong approach.

    If that's all your doing - a sub function call shouldn't be needed!


    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  3. #3
    SitePoint Addict
    Join Date
    Apr 2002
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh?
    I found this on a site, it works pretty good with another form but won't submit with that one.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •