SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Wizard dragonfly_7456's Avatar
    Join Date
    Dec 2002
    Location
    Moscow, USSR
    Posts
    1,092
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A form precheck?

    I have a personal message system set up on my site. The thing about it, is that when a person makes a new message, they are allowed to leave the subject blank. But, when the end user recieves the message, they have to click on the subject to read the message (The subject is used as the link to the messages' content).

    What I need, is some way to have the script check if the subject has been left blank, and if so, to give a javascript pop-up message with the given error, all without refreshing the page (And thus, loosing the content of the message).

    Here is the script:
    PHP Code:
    <?php
    ##################################################################
    ## Title........: myPMS II
    ## Description..: A Private Messaging System [PMS] for Mambo 4.5
    ## Author.......: Danial Taherzadeh
    ## Version......: 2.0 Beta
    ## Created......: 23/12/2003
    ## Contact......: [email="danialt@yahoo.com"]danialt@yahoo.com[/email]
    ## Mambo Version: 4.5 Stable
    ## Note: This script is a part of myPMS II package.
    ###################################################################
    defined'_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
    ?>

      <table width="100%" cellpadding="4" cellspacing="0" border="0" align="center" class="contentpane">
          <tr>
            <td colspan="2"><span class="contentheading"><?php echo _PMS_TITLE ?> : <?php echo _PMS_NEW ?></span></td>
          </tr>
      </TABLE>
    <?php
    echo _PMS_MENU;
    if (isset(
    $_POST['newsent']))
    {
     if (
    $_POST['recip'] == 'blank')
     {
      echo 
    _PMS_NO_REC;
     }
     else
     {
      
    $time date('H:i:s');
      
    $date date('Y-m-d');
            
    $_POST[newmsg]=nl2br(addslashes($_POST[newmsg]));
      
    $send "INSERT INTO #__pms (id,groupname,username,whofrom,date,time,readstate,subject,message) VALUES ('','','$_POST[recip]','$my->username','$date','$time','','$_POST[newsub]','$_POST[newmsg]')";
            
    $database->setQuery($send);
            
    $result $database->query();
            
    mosRedirect('index.php?option=com_pms&page=inbox'._PMS_MSG_SENT);
     }
    }

    $query="select username,name from #__users";
        
    $database->setQuery($query);
        
    $rows $database->loadObjectList();
    $users='<select class="inputbox" name="mylist" size=15 onChange="javascript:document.me.recip.value=document.me.mylist.value;"> ';
        foreach (
    $rows as $row1) {
    $users.="<option value=\"$row1->username\" ";
    if (
    $row1->username=="$_GET[id]")
    $users.= " SELECTED ";
    $users.=">$row1->username ($row1->name)</option>";
    }
    $users.="</select>";
    echo 
    '<p>';
    echo 
    '<table cellspacing="0" cellpadding="5" border="0" class="contentpane" style="border=1px solid #D0D0D0" align=center>';
    echo 
    '<form method="post" action="index.php?page=new&option=com_pms" name="me">';
    echo 
    '<tr class=sectiontableentry1>
    <td width=10%><b>'
    ._PMS_TO.':</b></td>';
    echo 
    "<td>
    <INPUT TYPE=\"TEXT\"  name=\"recip\" size=\"30\" class=\"inputbox\">
    </td>
    <td rowspan=5 width=100% class=\"sectiontableentry2\" Valign='top'>
    "
    ._PMS_SELECT."
    <br /><br />
    $users</td>";
    echo 
    '</td></tr>';
    echo 
    '<tr><td><b>'._PMS_SUBJECT.':</b></td>';
    echo 
    '<td><input type="text" class="inputbox" name="newsub" size=40></td></tr>';
    echo 
    '<tr  class=sectiontableentry1><td colspan=2><b>'._PMS_MESSAGE.':</b></td></tr>';
    echo 
    '<tr><td colspan=2><textarea name="newmsg" class="inputbox" rows=10 cols=50></textarea></td></tr>';
    echo 
    '<tr><td colspan=2><input type="submit" class=button name="newsent" value="'._PMS_SEND.'"></td></tr>';
    echo 
    '</table>';
    echo 
    '</form>';
    echo 
    '</p>';
    ?>
    Content Writing Service - Get custom SEO articles for 10$

  2. #2
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could use the onSubmit event in the form tag like so:
    <form .... onSubmit="return Check_subject(this)">

    And place a script in the head section of your document like this:
    <script type="javascript/text">
    function Check_subject(frmobj)
    {
    if(frmobj.newsub.value=="")
    {
    alert("Please provide a subject!")
    return false
    }
    }
    </script>

    When the submit button is clicked the onSubmit event would perform the function to check if the subject is empty and if it is popup an alert and then return false keeping the form from being submitted. IF the is something in the subject field then the form would be submitted.

  3. #3
    SitePoint Wizard dragonfly_7456's Avatar
    Join Date
    Dec 2002
    Location
    Moscow, USSR
    Posts
    1,092
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That didn't work.
    Content Writing Service - Get custom SEO articles for 10$

  4. #4
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The subject field should always be an optional field. You should consider using the username as the link to the messages' content instead of the subject line. That's how I have it set up on the message system for my website.
    Community Guidelines | Community FAQ

    "He that is kind is free, though he is a slave;
    he that is evil is a slave, though he be a king." - St. Augustine

  5. #5
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you get an error? Could you post a link to the page where you applied the javascript? That would help to see if there is something that is causing it to not work.

  6. #6
    SitePoint Wizard dragonfly_7456's Avatar
    Join Date
    Dec 2002
    Location
    Moscow, USSR
    Posts
    1,092
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Toly
    The subject field should always be an optional field. You should consider using the username as the link to the messages' content instead of the subject line. That's how I have it set up on the message system for my website.
    Well then, I have to make it so that when there is no subject that the system gives a "No Subject" message anyways, because its giving me a frigging blank space if there is no subject!! Thats not good from any way you look at it...
    Content Writing Service - Get custom SEO articles for 10$

  7. #7
    SitePoint Wizard dragonfly_7456's Avatar
    Join Date
    Dec 2002
    Location
    Moscow, USSR
    Posts
    1,092
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by requestcode
    Did you get an error? Could you post a link to the page where you applied the javascript? That would help to see if there is something that is causing it to not work.
    No error. The javascript didn't even function. As in, there was no popup when I didn't enter a subject.
    Content Writing Service - Get custom SEO articles for 10$

  8. #8
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dragonfly_7456
    Well then, I have to make it so that when there is no subject that the system gives a "No Subject" message anyways, because its giving me a frigging blank space if there is no subject!! Thats not good from any way you look at it...
    Something like (none) could work also, but I don't see the big deal on this.

    Anyways, did you change the "newsub" name to the name you gave it to your subject field? Both need to be the same.

    Code:
    <script type="javascript/text">
    function Check_subject(frmobj)
    {
    if(frmobj.subject.value=="")
    {
    alert("Please provide a subject!")
    return false
    }
    }
    </script>
    
    .....................
    
    <input type="text" name="subject" value="">

    And don't forget to add onSubmit="return Check_subject(this)" inside your form tag.
    Community Guidelines | Community FAQ

    "He that is kind is free, though he is a slave;
    he that is evil is a slave, though he be a king." - St. Augustine

  9. #9
    SitePoint Wizard dragonfly_7456's Avatar
    Join Date
    Dec 2002
    Location
    Moscow, USSR
    Posts
    1,092
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is what I got, and it still doesn't give me any popup!!!

    PHP Code:
    <?php
    ##################################################################
    ## Title........: myPMS II
    ## Description..: A Private Messaging System [PMS] for Mambo 4.5
    ## Author.......: Danial Taherzadeh
    ## Version......: 2.0 Beta
    ## Created......: 23/12/2003
    ## Contact......: [email="danialt@yahoo.com"]danialt@yahoo.com[/email]
    ## Mambo Version: 4.5 Stable
    ## Note: This script is a part of myPMS II package.
    ###################################################################
    defined'_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
    ?>
    <script type="javascript/text">
    function Check_subject(frmobj)
    {
    if(frmobj.newsub.value=="")
    {
    alert("Please provide a subject!")
    return false
    }
    }
    </script>
      <table width="100%" cellpadding="4" cellspacing="0" border="0" align="center" class="contentpane">
          <tr>
            <td colspan="2"><span class="contentheading"><?php echo _PMS_TITLE ?> : <?php echo _PMS_NEW ?></span></td>
          </tr>
      </TABLE>
    <?php
    echo _PMS_MENU;
    if (isset(
    $_POST['newsent']))
    {
     if (
    $_POST['recip'] == 'blank')
     {
      echo 
    _PMS_NO_REC;
     }
     else
     {
      
    $time date('H:i:s');
      
    $date date('Y-m-d');
            
    $_POST[newmsg]=nl2br(addslashes($_POST[newmsg]));
      
    $send "INSERT INTO #__pms (id,groupname,username,whofrom,date,time,readstate,subject,message) VALUES ('','','$_POST[recip]','$my->username','$date','$time','','$_POST[newsub]','$_POST[newmsg]')";
            
    $database->setQuery($send);
            
    $result $database->query();
            
    mosRedirect('index.php?option=com_pms&page=inbox'._PMS_MSG_SENT);
     }
    }

    $query="select username,name from #__users";
        
    $database->setQuery($query);
        
    $rows $database->loadObjectList();
    $users='<select class="inputbox" name="mylist" size=15 onChange="javascript:document.me.recip.value=document.me.mylist.value;"> ';
        foreach (
    $rows as $row1) {
    $users.="<option value=\"$row1->username\" ";
    if (
    $row1->username=="$_GET[id]")
    $users.= " SELECTED ";
    $users.=">$row1->username ($row1->name)</option>";
    }
    $users.="</select>";
    echo 
    '<p>';
    echo 
    '<table cellspacing="0" cellpadding="5" border="0" class="contentpane" style="border=1px solid #D0D0D0" align=center>';
    echo 
    '<form method="post" action="index.php?page=new&option=com_pms" name="me" onSubmit="return Check_subject(this)">';
    echo 
    '<tr class=sectiontableentry1>
    <td width=10%><b>'
    ._PMS_TO.':</b></td>';
    echo 
    "<td>
    <INPUT TYPE=\"TEXT\"  name=\"recip\" size=\"30\" class=\"inputbox\" value=\"
    $id\">
    </td>
    <td rowspan=5 width=100% class=\"sectiontableentry2\" Valign='top'>
    "
    ._PMS_SELECT."
    <br /><br />
    $users</td>";
    echo 
    '</td></tr>';
    echo 
    '<tr><td><b>'._PMS_SUBJECT.':</b></td>';
    echo 
    '<td><input type="text" class="inputbox" name="newsub" size=40></td></tr>';
    echo 
    '<tr  class=sectiontableentry1><td colspan=2><b>'._PMS_MESSAGE.':</b></td></tr>';
    echo 
    '<tr><td colspan=2><textarea name="newmsg" class="inputbox" rows=10 cols=50></textarea></td></tr>';
    echo 
    '<tr><td colspan=2><input type="submit" class=button name="newsent" value="'._PMS_SEND.'"></td></tr>';
    echo 
    '</table>';
    echo 
    '</form>';
    echo 
    '</p>';
    ?>
    Content Writing Service - Get custom SEO articles for 10$

  10. #10
    SitePoint Wizard dragonfly_7456's Avatar
    Join Date
    Dec 2002
    Location
    Moscow, USSR
    Posts
    1,092
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Never mind, I found a work around. I've made the default value of subject "No Subject", with an out disappear/reappear javascript running. (Like the search box at the top of sitepointforums.com.

    Hey, it works...
    Content Writing Service - Get custom SEO articles for 10$


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
  •