PHP form problem :(

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LoRdGd
    New Member
    • Mar 2008
    • 29
    • 3.6.x

    PHP form problem :(

    Hello.
    Last days i`m loosing my whole free time in one thing.
    I want to have a form witch will alble to creating a posts in my forum.

    The forum is on site based on Joomla, but i think i does`nt matter.

    This is my code:

    PHP Code:
    <?
    error_reporting
    (2047);
    ?>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
    <title>Formularz zgłoszeniowy na Opiekuna</title>
    </head>

    <body onload="datetime()">

    <form name="formzgloszenie" method="post" action="" onSubmit="sprawdz(this); return false;">
    <table border="0" width="100%" class="style1">
      <tr>
        <td width="40%"><b>Zgłaszający:</b></td>
        <td><INPUT type="hidden" name="data" id="data" size=40 maxlength=25 value="Ładowanie daty" ></td>
      </tr>
      <tr>
        <td width="15%">Imię:</td>
        <td><input type="text" name="imie" id="imie" size=40></td>
      </tr>
      <tr>
        <td>Twój nick na forum Arachnea.org (jeżeli posiadasz):</td>
        <td><input type="text" name="nick" id="nick" size=40></td>
      </tr>
      <tr>
        <td>Jakiego pająka posiadasz lub chcesz kupić:</td>
        <td><input type="text" name="pajaki" id="pajaki" size=40></td>
      </tr>
      <tr>
        <td>W paru zdaniach napisz jakiej pomocy oczekujesz:</td>
        <td><textarea name="doswiadczenie" id="doswiadczenie" cols="30" rows="3"></textarea></td>
      </tr>
      <tr>
        <td>Twój adres e-mail:</td>
        <td><input type="text" name="email" id="email" size=40></td>
      </tr>
      <tr>
        <td>Twój numer komunikatora np. gadu-gadu:</td>
        <td><input type="text" name="gg" id="gg" size=40></td>
      </tr>  
      <tr>
        <td>Jaki jest Twój wiek?</td>
        <td><input type="text" name="wiek" id="wiek" size=40></td>
      </tr>
      <tr>
        <td>Czy hodujesz jakieś inne zwierzęta egzotyczne?</td>
        <td><input type="text" name="inne" id="inne" size=40></td>
      </tr>
      <tr>
        <td>Skąd dowiedziałeś się o tym projekcie lub kto Cię do niego zachęcił?</td>
        <td><input type="text" name="zacheta" id="zacheta" size=40></td>
      </tr>
      <tr>
        <td>Preferowany kontakt:</td>
        <td>
          <input type="radio" name="kontakt" value="e-mail" size=40>
          E-mail
          <br>
          <input type="radio" name="kontakt" value="komunikator" size=40 checked>
          Komunikator
          <br>
          <input type="radio" name="kontakt" value="obojetne" size=40>
          Obojętne
        </td>
      </tr>
      <tr>
        <td>Zgoda na przetwarzanie danych ososbowych potrzebnych do realizacji tego projektu:</td>
        <td>
          <input type="radio" name="zgoda" value="TAK" size=40 checked>
          TAK
          <br>
          <input type="radio" name="zgoda" value="NIE" size=40>
          NIE
          <br>
        </td>
      </tr>  
    </table>
      <input type="reset" value="Wyczyść formularz" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="submit" type="submit" value=">> Wyślij zgłoszenie <<"/ >

    </form>


    <script language="javascript" type="text/javascript">
    function sprawdz(formularz)
        {
        if(formularz.imie.value.length<2)
            {
            alert("Podana wartość imienia: "+formularz.imie.value+"\n\n"+"Imię musi mieć min. 2 znaki!"); formularz.imie.select();
            return false;
            }
        if(formularz.pajaki.value=='')
            {
            alert("Napisz jakiego pająka już posiadasz lub chcesz kupić!"); formularz.pajaki.select();
            return false;        
            }           
        if(formularz.doswiadczenie.value=='')
            {
            alert("Napisz jakiej pomocy oczekujesz - przynajmniej kilka słów!"); formularz.doswiadczenie.select();
            return false;        
            }
        if(formularz.email.value=='')
            {
            alert("Koniecznie podaj Twój adres e-mail!"); formularz.email.select();
            return false;        
            }
        if(formularz.gg.value=='')
            {
            alert("Koniecznie podaj Twój numer komunikatora np. gg! Jeśli nie posiadasz, to napisz numer swojego telefonu"); formularz.gg.select();
            return false;        
            }    
        if(formularz.inne.value=='')
            {
            alert("Napisz, czy hodujesz jakieś inne zwierzęta!"); formularz.inne.select();
            return false;        
            }
        if(formularz.zacheta.value=='')
            {
            alert("Skąd do nas trafiłeś?"); formularz.zacheta.select();
            return false;        
            }
                        
      if (formularz.email.value.length==0)
       {
       alert("Wprowadź adres e-mail!"); formularz.email.select();
       return false;
       } else
       {
       i=formularz.email.value.indexOf("@");
       j=formularz.email.value.indexOf(".",i);
       k=formularz.email.value.indexOf(",");
       kk=formularz.email.value.indexOf(" ");
       jj=formularz.email.value.lastIndexOf(".")+1;
       len=formularz.email.value.length;
       }
      if ((i>0) && (j>(1+1)) && (k==-1) && (kk==-1) && (len-jj >=2) && (len-jj<=3))
       {
       }
      else
       {
       alert("Błędny adres e-mail - sprawdź jego poprawność:  "+"\n\n" + formularz.email.value); formularz.email.select();
      return false;
       }

     if((formularz.kontakt[0].checked==formularz.kontakt[1].checked)&&(formularz.kontakt[1].checked==formularz.kontakt[2].checked))
            {
            alert("Podaj preferencyjny kontakt z Tobą");
            return false;        
            }

                   
        alert("Dziękujemy, Twoje zgłoszenie zostało wysłane. \n\n Niedługo ktoś się z Tobą skontaktuje." );
              
        formularz.submit();        
        }
    </script>


    <script language="javascript">
     function datetime(){
      var datetime = new Date()
      var hr = datetime.getHours()
        var min = datetime.getMinutes()
      var mon = datetime.getMonth()
      var monNames = new Array("styczeń", "luty", "marzec", "kwiecień", "maj", "czerwiec", "lipiec", "sierpień", "wrzesień", "październik", "listopad", "grudzień");
      var day = datetime.getDate()
      var year = datetime.getFullYear()
      if(hr < 10){
        hr = " " + hr
        }
      if(min < 10){
        min = "0" + min
        }

      document.formzgloszenie.data.value = hr + ":" + min + "   " + day + " " + monNames[mon]+ " " + " " + year
      setTimeout("datetime()", 1000)
      }
    </script>



    <?
        
    if(isset($_POST['nick']))
            {
            
    $wiadomosc='Data zgłoszenia: '.$_POST['data'] . "\n\r" 'Imię: ' $_POST['imie']. "\n\r" 'Nick: ' $_POST['nick'] . "\n\r" 'Pająki: ' $_POST['pajaki'] . "\n\r" .'Oczekiwania: ' $_POST['doswiadczenie'] . "\n\r" 
                   
    'E-mail: ' $_POST['email']. "\n\r" 'Komunikator: ' $_POST['gg']. "\n\r" .'Wiek: ' $_POST['wiek'] . "\n\r" 'Inne zwierzęta egzotyczne: ' $_POST['inne']. "\n\r" 
                   
    'Preferowany kontakt: ' $_POST['kontakt'] . "\n\r" .'Zgłoszenie dzięki: ' $_POST['zacheta']. "\n\r" 'Zgoda na przetwarzanie danych: ' $_POST['zgoda'];
                           
            
    mail('[email protected]','Zgłoszenie kandydata na Opiekuna',$wiadomosc,'From: '.$_POST['nick']." <".$_POST['email']." >"."\n".'CC: '.$_POST['email']);

            
    $f=fopen('KandydaciNaPodopiecznego.txt''a');
            
    fwrite($f$wiadomosc "\n\r\n\r");
            
    fclose($f);
            }
            
    require_once(
    './forum/global.php');
    require_once(
    './forum//includes/class_dm.php');
    require_once(
    './forum/includes/class_dm_threadpost.php'); 
            
           
    $postdm = new vB_DataManager_Post($vbulletinERRTYPE_STANDARD); 

    $timenow TIMENOW ;
    $threadinfo fetch_threadinfo($threadid);
    $foruminfo fetch_foruminfo($forumid);
    $threadid '19987';
    $userid '1500';

    $postdm->set_info('forum'$foruminfo);
    $postdm->set_info('thread'$threadinfo);  
    $postdm->set('threadid'$threadid);
    $postdm->set('title'$symid);
    $postdm->set('userid'$userid);
    $postdm->set('pagetext'$wiadomosc);
    $postdm->set('allowsmilie'1);
    $postdm->set('visible'1);
    $postdm->set('dateline'$timenow);
    $postdm->save();
    unset(
    $postdm);
     
    ?>

    </body>
    </html>
    This is an code for page guestes, and its sending email with entered data, and writing the data to a .txt file.

    In vbulletin.org nobady know/dont want to help me.
    This is very importnant think for me, so if somebody know why this red part of code dont want to work, and know how to repair it, please help me.

    Some additional informations:

    .php file is in my domain root directory.
    forum is instaled in domain_root/forum/
    userid - its my id.
    threadid - my specialy created thread in visible forums.

    PS. All this general code was created by ex-administrator. Im a newbie in php.
  • LoRdGd
    New Member
    • Mar 2008
    • 29
    • 3.6.x

    #2
    Helo
    I have done it by myself
    For my offsprings:

    The file with code must be directly in /forum/ directory. Before i have it in my root, but someone tells me it can have a matter.

    PHP Code:
    require_once('./global.php');
    require_once(
    './includes/class_dm.php');
    require_once(
    './includes/class_dm_threadpost.php'); 
            
           
    $postdm = new vB_DataManager_Post($vbulletinERRTYPE_STANDARD); 

    $timenow TIMENOW ;
    $threadinfo fetch_threadinfo($threadid);
    $foruminfo fetch_foruminfo($forumid);
    $threadid '19987';
    $userid '1500';

    $postdm->set_info('forum'$foruminfo);
    $postdm->set_info('thread'$threadinfo);  
    $postdm->set('threadid'$threadid);
    $postdm->set('title'$symid);
    $postdm->set('userid'$userid);
    $postdm->set('pagetext'$wiadomosc);
    $postdm->set('allowsmilie'1);
    $postdm->set('visible'1);
    $postdm->set('dateline'$timenow);
    $postdm->save();
    unset(
    $postdm); 
    Regards

    Comment

    • DoE
      Senior Member
      • Sep 2007
      • 763

      #3
      Thanks for posting the solution, there will always be someone searching for an answer simular to your question here,

      Comment

      • LoRdGd
        New Member
        • Mar 2008
        • 29
        • 3.6.x

        #4
        Creating threads

        Another code, for creating threads in specyfic forum:

        PHP Code:
                mail('[email protected]','Zgłoszenie kandydata na Opiekuna',$wiadomosc,'From: '.$_POST['nick']." <".$_POST['email']." >"."\n".'CC: '.$_POST['email']);

                
        $f=fopen('KandydaciNaPodopiecznego.txt''a');
                
        fwrite($f$wiadomosc "\n\r\n\r");
                
        fclose($f);
                } 




                




            if(isset(
        $_POST['nick']))
                {
        require_once(
        './global.php');
        require_once(
        './includes/class_dm.php');
        require_once(
        './includes/class_dm_threadpost.php'); 
        require_once(
        './includes/functions_databuild.php');
                
                
        $wiadomosc='Data zgłoszenia: [b]'.$_POST['data'] . "\n\r" '[/b]Imię: [b]' $_POST['imie']. "\n\r" '[/b]Nick: [b]' $_POST['nick'] . "\n\r" '[/b]Pająki: [b]' $_POST['pajaki'] . "\n\r" .'[/b]Oczekiwania: [b]' $_POST['doswiadczenie'] . "\n\r" 
                       
        '[/b]E-mail: [b]' $_POST['email']. "\n\r" '[/b]Komunikator: [b]' $_POST['gg']. "\n\r" .'[/b]Wiek: [b]' $_POST['wiek'] . "\n\r" '[/b]Inne zwierzęta egzotyczne: [b]' $_POST['inne']. "\n\r" 
                       
        '[/b]Preferowany kontakt: [b]' $_POST['kontakt'] . "\n\r" .'[/b]Zgłoszenie dzięki: [b]' $_POST['zacheta']. "\n\r" '[/b]Zgoda na przetwarzanie danych: [b]' $_POST['zgoda']."[/b]";
                

        $forumid '130';
        if(
        strlen($_POST['nick'])>=1) { $posttitle 'Podopieczny: '.$_POST['nick'];}
        else if(isset(
        $_POST['imie'])) { $posttitle 'Podopieczny: '.$_POST['imie'];}
        else 
        $posttitle 'Podopieczny';
        $postpagetext $wiadomosc;
        $postuserid '1088';
        $foruminfo fetch_foruminfo($forumid);

        $threadinfo = array();
            
        $foruminfo fetch_foruminfo($forumid);
            
        $threaddm =& datamanager_init('Thread_FirstPost'$vbulletinERRTYPE_ARRAY'threadpost');
            
        $threaddm->set('forumid'$forumid);
            
        $threaddm->set('userid'$postuserid);
            
        $threaddm->set('pagetext'$postpagetext);
            
        $threaddm->set('title'$posttitle);
            
        $threaddm->set('allowsmilie''1');
            
        $threaddm->set('visible''1');
            
        $threaddm->set_info('forum'$foruminfo);
            
        $threaddm->pre_save();

            if(
        count($threaddm->errors) < 1)
            {
                
        $threadid $threaddm->save();
                
        build_thread_counters($threadid);
            }

            
        build_forum_counters($forumid);
            unset(
        $threadid);
            }

        ?>

        </body>
        </html> 
        This code is a bottom part of my code from 1st post.
        This code creating threads in forumid=130(ZGLOSZENIA), userid=1088(aTahualpa).
        Threads topic are "Podopieczny + [imie]field"

        Screen form my page:

        Screen from generated thread in forum:
        Last edited by LoRdGd; Wed 18 Jun '08, 7:12pm.

        Comment

        Related Topics

        Collapse

        Working...