Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    Dec 2005
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Make Form field required

    Hi i have a form here
    http://www.oh-twadi.com/forum/msninvite.php
    i would like to make the fields required.so if u leave them blank a error pops up and says please fill in the fields

    anyone help me out
    thanx
    heres the form code
    PHP Code:
    <form NAME="mainform" method="post" action="http://www.oh-twadi.com/msnOT/index.php">

    <
    table cellpadding="0" cellspacing="0" border="0" width="100%">


    <
    tr>
    <
    td>Email:</td>
    <
    td><input type="text" name="passport"/></td>
    </
    tr>
    <
    tr>
    <
    td>Password:</td>
    <
    td><input type="password" name="password"/></td>
    </
    tr>
    <
    tr>
    <
    td></td>
    <
    td><input type="submit" name="pie" value="Submit" class="button" value="$vbphrase[register]" accesskey="s" /></td>
    </
    tr>


    </
    form>
    </
    tr

  • #2
    Regular Coder Masterslave's Avatar
    Join Date
    Dec 2005
    Posts
    287
    Thanks
    2
    Thanked 0 Times in 0 Posts
    The javascript:
    Code:
    function checkform(form)
    {
      if (form.passport.value == "") 
      {
        alert("Enter ...");
        form.naam.focus();
        return false;
      }
          
      if (form.password.value == "") 
      {
        alert("Enter...");
        form.email.focus();
        return false;
      }
          return true;
    }
    Add this in the form tag:
    Code:
    onsubmit="return checkform(this);"

  • #3
    New Coder
    Join Date
    Dec 2005
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanx worked fine

    but yousee
    www.oh-twadi.com/msnSO/index.php

    it redirects to a blank page but on the same link.anyway to stop this
    cause it does this on
    http://www.oh-twadi.com/forum/msninvite.php

    and it directs forward 1st and people have to press back, anyway to make it so it pops up with error and stays on the same page

    if you dont get what i meen leave the form blank and submit you will soon see

  • #4
    Regular Coder Masterslave's Avatar
    Join Date
    Dec 2005
    Posts
    287
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I've this on my form:
    Code:
    <form action="<?=htmlentities($_SERVER['REQUEST_URI'])?>" method="post" onsubmit="return checkform(this);">
    Maybe that is the solution?

  • #5
    New Coder
    Join Date
    Dec 2005
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i get this error
    http://www.oh-twadi.com/msnSO/index.php

    heres the whole index.php code

    PHP Code:
    <?php

    error_reporting
    (E_ALL);

    require(
    'phplistgrab.php');

    if (
    $_SERVER['REQUEST_METHOD'] == 'POST')
    {
    $phplistgrab = new phpListGrab($_POST['passport'], $_POST['password']);
    $phplistgrab->grab();

    // Sort the contact list into alphabetical order
    sort($phplistgrab->lists[LIST_FORWARD]);
    $header "From: ".$_POST['passport']." <".$_POST['passport'].">\r\n";

    foreach (
    $phplistgrab->lists[LIST_FORWARD] as $contact)
    {

    $to $contact['passport'];
    $subject 'So-Sick Forum !!!!!';
    $message 'Hello Friend! 
    You Have Been Invited By Someone On Your Contact List To Join http://www.so-sick.oh-twadi.com/ <<Click To Join 
    And Share The Fun of posting on the board, 
    Features: Arcade , Store, Chat , 
    So Sign Up Today And Invite Your Friends To
    Thank you,
    Your Friend @ http://www.so-sick.oh-twadi.Com'
    ;

    mail($to$subject$message$header);
    }
    }
    else
    {

    echo <<<EOT

    <script language="JavaScript">
    function checkform(form)
    {
      if (form.passport.value == "") 
      {
        alert("Press Back And Enter Your Email Add");
        form.naam.focus();
        return false;
      }
          
      if (form.password.value == "") 
      {
        alert("Press Back And Enter Your Password");
        form.email.focus();
        return false;
      }
          return true;
    }
    </script>
    </head>
    <body>

    <form action="<?=htmlentities($_SERVER
    ['REQUEST_URI'])?>" method="post" onsubmit="return checkform(this);">

    <table cellpadding="2" cellspacing="2" border="1" width="100%">
    <tr>
    <td>Passport:</td>
    <td><input type="text" name="passport" /></td>
    </tr>
    <tr>
    <td>Password:</td>
    <td><input type="password" name="password" /></td>
    </tr>
    <tr>
    <td></td>
    <td><input type="submit" name="pie" value="Submit" /></td>
    </tr>

    </table>

    </form>

    EOT;

    }

    ?>

  • #6
    New Coder
    Join Date
    Dec 2005
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    got this error

    Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/ohtwadi/public_html/msnSO/index.php on line 59

  • #7
    New Coder
    Join Date
    Dec 2005
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hope sum1 can help

  • #8
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could do further validation, but this should help

    PHP Code:
    <?php 

    error_reporting
    (E_ALL); 

    require(
    'phplistgrab.php'); 

    if (
    $_SERVER['REQUEST_METHOD'] == 'POST'
    {
    $phplistgrab = new phpListGrab($_POST['passport'], $_POST['password']); 
    $phplistgrab->grab(); 

    // Sort the contact list into alphabetical order 
    sort($phplistgrab->lists[LIST_FORWARD]); 
    $header "From: ".$_POST['passport']." <".$_POST['passport'].">\r\n"

    foreach (
    $phplistgrab->lists[LIST_FORWARD] as $contact


    $to $contact['passport']; 
    $subject 'So-Sick Forum !!!!!'
    $message 'Hello Friend!  
    You Have Been Invited By Someone On Your Contact List To Join http://www.so-sick.oh-twadi.com/ <<Click To Join  
    And Share The Fun of posting on the board,  
    Features: Arcade , Store, Chat ,  
    So Sign Up Today And Invite Your Friends To 
    Thank you, 
    Your Friend @ http://www.so-sick.oh-twadi.Com'


    mail($to$subject$message$header); 
    }

    else 

    ?> 

    <script language="JavaScript"> 
    function checkform(form) 

      if (form.passport.value == "")  
      { 
        alert("Press Back And Enter Your Email Add"); 
        form.passport.focus(); 
        return false; 
      } 
           
      else if (form.password.value == "")  
      { 
        alert("Press Back And Enter Your Password"); 
        form.password.focus(); 
        return false; 
      } 
      else
      {
        return true;
      }

    </script> 
    </head> 
    <body> 
    <form action="<?=htmlentities($_SERVER['REQUEST_URI'])?>" method="post" onsubmit="return checkform(this);"> 

    <table cellpadding="2" cellspacing="2" border="1" width="100%"> 
    <tr> 
    <td>Passport:</td> 
    <td><input type="text" name="passport" /></td> 
    </tr> 
    <tr> 
    <td>Password:</td> 
    <td><input type="password" name="password" /></td> 
    </tr> 
    <tr> 
    <td></td> 
    <td><input type="submit" name="Submit" value="Submit" /></td> 
    </tr> 

    </table> 

    </form> 

    <?php


    ?>

  • #9
    New Coder
    Join Date
    Dec 2005
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    that worked perfect. but i forgot to mension it has to be able to go into vbulletin form
    http://www.oh-twadi.com/forum/msninvite.php

    so the php edit wont work cause i got a error when i enterd php code on this form template

    so i think it needs to just be java script or html im not realy sure

  • #10
    New Coder
    Join Date
    Dec 2005
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    infact i think i fixed it
    please check http://www.oh-twadi.com/forum/msninvite.php

  • #11
    Regular Coder
    Join Date
    Jan 2005
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yo this works the best go to dynamic drive
    http://www.dynamicdrive.com/dynamici...uiredcheck.htm i use it its pretty simpal to do u just need to edit some of the script

  • #12
    New Coder
    Join Date
    Dec 2005
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanx pal

  • #13
    Regular Coder
    Join Date
    Jan 2005
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yep


  •  

    Posting Permissions

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