Problem with Forms and PHP

Hi there, I need some help here. I have a form that doesn’t save some choices when submitted into the input boxes.
This is the form: http://s14.postimg.org/ndyqfjj29/form.png
This is the template I’m using

$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
$headinclude
<title>$vboptions[bbtitle] - $formtitle</title>
</head>
<body>
$header
$navbar


<!-- main -->
<if condition="$preview">
<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<tr>
    <td class="tcat">
        Anteprima Richiesta
    </td>
</tr>
<tr>
    <td class="alt1">
$preview
</td>
</tr>
</table>
</if>

<br />
<form name="vbform" action="newthread.php" method="post"<if condition="!is_browser('webtv')"> onsubmit="return vB_Editor['$editorid'].prepare_submit(0, $vboptions[postminchars])"</if>>
<input type="hidden" value="$formname" name="do" />
<input type="hidden" value="submit" name="action" />

<input type="hidden" name="posthash" value="$posthash" />
<input type="hidden" name="poststarttime" value="$poststarttime" />
<input type="hidden" name="securitytoken" value="$bbuserinfo[securitytoken]" />

<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<tr>
    <td class="tcat" colspan="3">
        $vboptions[bbtitle] - $formtitle
    </td>
</tr>
<tr>
    <td class="panelsurround" align="center" colspan="3">

    <table class="panel" cellpadding="0" cellspacing="$stylevar[formspacer]" border="0" width="100%">
    <tr>
        <td align="$stylevar[left]">
            
                <table cellpadding="0" cellspacing="$stylevar[formspacer]" border="0">
                <tr>
                    <td>
                        $formpurpose

                    </td>
                </tr>
        </table>
    
</td>
</tr>
</table>
</td>
</tr>
</table>
<br />
<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">

<tr>
    <td class="alt1" width="50%">
                <b>$domanda_urlwd</b>
        </td>
        <td class="alt1" width="50%">
                 <b>Richiedente:</b>
                </td>
    </tr>
<tr>
<td class="alt2" width="50%">
Inserisci qui l'URL del tuo sito: <input type="text" size="30" value="$risposta_urlwd" name="risposta_urlwd" /><br />
Inserisci qui il Titolo del tuo sito: <input type="text" size="30" value="$risposta_titolowdwd" name="risposta_titolowd" />
</td>
<td class="alt2" width="50%">
L'username con il quale stai richiedendo il servizio: <b>$bbuserinfo[username]</b>
</td>
</tr>

<tr>
<td class="alt1" width="50%"><strong>$domanda_categoriawd</strong></td>
<td class="alt1" width="50%">

<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td><input type="radio" name="risposta_categoriawd" value="$scelta_categoriawda" <if condition="$scelta_categoriawda == $risposta_categoriawd">checked="checked"</if> /> $scelta_categoriawda </td>
<td><input type="radio" name="risposta_categoriawd" value="$scelta_categoriawdb" <if condition="$scelta_cetagoriawdb == $risposta_categoriawd">checked="checked"</if> /> $scelta_categoriawdb </td>
<td>&nbsp;</td>
</tr>
</table>
</td>

<tr>
<td class="alt2" valign="middle" width="50%">
<b>$vbtextquestion</b><br />
$vbtextexplain
</td>
<td class="alt2" width="50%">
<div align="center">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>

<div style="padding: 5px; border: solid 2px red" class="smallfont"><strong>Nota</strong>: questa richiesta sar&agrave; visualizzabile solo allo staff di Klayz. Le informazioni private e sensibili (account amministrativo, dati FTP, etc) non saranno in alcun modo divulgate. Inserite pure i dati sensibili nel box di testo qui sotto, se necessario. Grazie per la collaborazione.</div><br />

$messagearea
<br />
<if condition="$attachmentoption">
<div style="width:100%" align="$stylevar[left]">$attachmentoption</div>
</if>
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td class="alt1" colspan="3">
<p align="center">
<input type="submit" value="Invia Richiesta" name="submit" style="font-family: Verdana; font-size: 10pt" class="button" />
<input type="submit" value="Anteprima Richiesta" name="submit" style="font-family: Verdana; font-size: 10pt" class="button" />
</p></td></tr>
</table>

</form>


$footer
</body>
</html>

and this is the plugin that makes it work:

$formname = "invio_directory";

if ($_REQUEST['do'] == $formname)
{


$vbulletin->input->clean_array_gpc('p', array(
'risposta_urlwd' => TYPE_STR,
'risposta_titolowd' => TYPE_STR,
'risposta_categoriawd' => TYPE_STR,
));


$risposta_urlwd = $vbulletin->GPC['risposta_urlwd'];
$risposta_titolowd = $vbulletin->GPC['risposta_titolowd'];
$risposta_categoriawd = $vbulletin->GPC['risposta_categoriawd'];


if (!in_array($vbulletin->userinfo['usergroupid'], array(5,6,7,2,15))) print_no_permission();

$maintemplate = "form_invio_directory";

$answertemplate = "formanswers_invio_directory";

//ENABLE FORM TO BE POSTED - 1 = yes, 0 = no
$formforum = "1";

$formforumid = "143";

//ENABLE POLL TO BE CREATED - 1 = yes, 0 = no
$formpoll = "0";
$polloption[1] = "Yes";
$polloption[2] = "No";
$polloption[3] = "Maybe";

//Make poll public - 1 = yes, 0 = no
$pollpublic = "0";

//ENABLE FORM TO REPLY TO EXISTING THREAD - 1 = yes, 0 = no
$formreply = "0";

//EXISTING THREAD ID FOR FORM TO REPLY IN
$formreplythreadid = "12345";

//ENABLE FORM TO BE PMED (guests CANNOT use this option) - 1 = yes, 0 = no
$formpm = "0";

//USERNAME TO PM TO (separate multiple usernames with a ';')
$formpmname = "Abe";

//ENABLE FORM TO BE EMAILED - 1 = yes, 0 = no
$formemail = "0";

//EMAIL ADDRESS TO EMAIL TO (separate multiple usernames with a ';')
$formemailaddress = "youremail@yourforums.com";

//ENABLE ATTACHMENTS - 1 = yes, 0 = no
//attachments can only be used if the form is going to make a new thread or post
$allow_attachments = "1";

//REDIRECT OPTIONS:
// 0 - thank you message (thread, reply, pm, or email)
// 1 - redirect to post (thread or reply)
// 2 - redirect to thread (thread only)
// 3 - redirect to forum (thread only)
// 4 - redirect to editpost (thread or reply)

$redirectoption = "0";

$errormessage = "Il tuo link &egrave; stato inviato correttamente alla Directory! Grazie per il tuo invio!<br /><br /><a href=\"index.php\">Torna alla Home della Community</a>"; //This is the thank you message

//FORCE USER TO ANSWER ALL QUESTIONS - 1 = yes, 0 = no

$answerall = "1";


$formtitle = "Richiesta per directory";

$posttitle = "$formtitle";

$formpurpose = "Richiedi di entrare nella nostra directory con il tuo sito web, forum o blog! Una volta riempito il form e inviato, verr&agrave; creato in automatico un thread di richiesta (visibile solo ai membri dello staff). Ogni richiesta verr&agrave; valutata dallo staff della community. Se idonea il link verr&agrave; aggiunto alla Web Directory al pi&ugrave; presto.<br /><br />


<strong>Nota:</strong> Lo staff di Klayz.com non &egrave; pagato per offrire questo servizio, dunque abbiate pazienza e non aspettatevi in tutti i casi un pronto intervento.";

$domanda_urlwd = "Il tuo Sito";
$domanda_titolowd = "Titolo";
$domanda_categoriawd = "Scegli Categoria";
$scelta_categoriawda = "yes";
$scelta_categoriawdb = "no";


$vbtextquestion = "La tua richiesta..<br />";
$vbtextexplain = "Inserisci nel box qui a destra una descrizione dettagliata del tuo sito web (blog, forum o portale). <br /><br />
La descrizione pu&ograve; contenere un <strong>massimo di 40 parole</strong>. Descrizioni ben scritte e dettagliate aiutano l'indicizzazione del tuo sito web e la possibilit&agrave; che la richiesta venga approvata. Alcune regole da seguire:
<ul>
    <li>Non usare tag HTML. Puoi usare i Codici BB (in modo moderato)</li>
    <li>Scrivi sentenze intere e frasi con una grammatica e una punteggiatura corretta.</li>
    <li>Non scrivere TUTTO IN MAIUSCOLO</li>
    <li>Evita di usare la maiuscola per ogni inizio parola in una frase.</li>
    <li>Evita di utilizzare linguaggi di promozione come il miglior sito, il forum pi&ugrave; bello - saranno rimossi.</li>
</ul>";

if ($_REQUEST['action'] == '')
{
  $_REQUEST['action'] = "form";
}


$bbuserinfo = $vbulletin->userinfo;

// start navbar
$navbits = array();
$navbits['newthread.php?' . $vbulletin->session->vars['sessionurl'] . "do=$formname"] = $formtitle;

$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');

if ($_REQUEST['action'] == "submit")
{

    if ($answerall == "1")
    {
        if ($risposta_urlwd == '' OR $risposta_titolowd == '' OR $risposta_categoriawd == '')
        {
            $errormessage = "$bbuserinfo[username], devi compilare tutti i campi per poter iviare il tuo link! Torna indietro e correggi i campi.";
            eval('print_output("' . fetch_template('STANDARD_ERROR') . '");');
            exit();
        }
    }

    $vbulletin->input->clean_array_gpc('p', array(
        'wysiwyg'            => TYPE_BOOL,
        'message'            => TYPE_STR
        ));

    if ($vbulletin->GPC['wysiwyg'])
    {
        require_once(DIR . '/includes/functions_wysiwyg.php');
        $vbtextanswer = convert_wysiwyg_html_to_bbcode($vbulletin->GPC['message'], $foruminfo['allowhtml']);
    }
    else
    {
        $vbtextanswer =& $vbulletin->GPC['message'];
    }

    eval('$formsend = "' . fetch_template("$answertemplate", 0, false) . '";');

    $posthash = $vbulletin->input->clean_gpc('p', 'posthash', TYPE_NOHTML);
    $poststarttime = $vbulletin->input->clean_gpc('p', 'poststarttime', TYPE_UINT);

    if ($_POST['submit'] == 'Invia Richiesta')
    {
        if ($formforum == "1")
        {
            $foruminfo = verify_id('forum', $formforumid, 0, 1);
            $forumperms = fetch_permissions($foruminfo[forumid]);
            $newpost['username'] =& $vbulletin->userinfo['username'];

            $newpost['message'] =& $formsend;
            $newpost['title'] =& $posttitle;
            $newpost['parseurl'] = '1';
            $newpost['poststarttime'] = $poststarttime;
            $newpost['posthash'] = $posthash;

            if ($vbulletin->userinfo['autosubscribe'] != -1)
            {
                $newpost['emailupdate'] = $vbulletin->userinfo['autosubscribe'];
            }
            else
            {
                $newpost['emailupdate'] = 9999;
            }

            if ($vbulletin->userinfo['signature'] != '')
            {
                $newpost['signature'] = '1';

            }
            else
            {
                $newpost['signature'] = '0';
            }

            build_new_post('thread', $foruminfo, array(), array(), $newpost, $errors);

            if ($formpoll == "1")
            {

                $threadinfo = verify_id('thread', $newpost[threadid], 0, 1);
                $polloptions = count($polloption);
                $question = $posttitle;
                $vbulletin->GPC['options'] = $polloption;

                $counter = 0;
                $optioncount = 0;
                $badoption = '';
                while ($counter++ < $polloptions)
                { // 0..Pollnum-1 we want, as arrays start with 0
                    if ($vbulletin->options['maxpolllength'] AND vbstrlen($vbulletin->GPC['options']["$counter"]) > $vbulletin->options['maxpolllength'])
                    {
                        $badoption .= iif($badoption, ', ') . $counter;
                    }
                    if (!empty($vbulletin->GPC['options']["$counter"]))
                    {
                        $optioncount++;
                    }
                }

                // Add the poll
                $poll =& datamanager_init('Poll', $vbulletin, ERRTYPE_STANDARD);

                $counter = 0;
                while ($counter++ < $polloptions)
                {
                    if ($vbulletin->GPC['options']["$counter"] != '')
                    {
                        $poll->set_option($vbulletin->GPC['options']["$counter"]);
                    }
                }

                $poll->set('question',    $question);
                $poll->set('dateline',    TIMENOW);
                $poll->set('active',    '1');
                $poll->set('public',    $pollpublic);

                $pollid = $poll->save();
                //end create new poll

                // update thread
                $threadman =& datamanager_init('Thread', $vbulletin, ERRTYPE_STANDARD, 'threadpost');
                $threadman->set_existing($threadinfo);
                $threadman->set('pollid', $pollid);
                $threadman->save();
            }
        }

        if ($formreply == "1")
        {
            $threadinfo = verify_id('thread', $formreplythreadid, 0, 1);
            $forumperms = fetch_permissions($threadinfo[forumid]);
            $newpost['username'] =& $vbulletin->userinfo['username'];
            $newpost['message'] =& $formsend;
            $newpost['title'] =& $posttitle;
            $newpost['parseurl'] = "1";
            $newpost['poststarttime'] = $poststarttime;
            $newpost['posthash'] = $posthash;
        
            if ($vbulletin->userinfo['autosubscribe'] != -1)
            {
                $newpost['emailupdate'] = $vbulletin->userinfo['autosubscribe'];
            }
            else
            {
                $newpost['emailupdate'] = 9999;
            }

            if ($vbulletin->userinfo['signature'] != '')
            {
                $newpost['signature'] = '1';
            }
            else
            {
                $newpost['signature'] = '0';
            }

            build_new_post('reply', $foruminfo, $threadinfo, $postinfo, $newpost, $errors);
        }

        if ($formpm == "1")
        {
            $vbulletin->GPC['message'] =& $formsend;
            $vbulletin->GPC['title'] =& $posttitle;
            $vbulletin->GPC['recipients'] =& $formpmname;

            $pm['message'] =& $vbulletin->GPC['message'];
            $pm['title'] =& $vbulletin->GPC['title'];
            $pm['recipients'] =& $vbulletin->GPC['recipients'];

            // create the DM to do error checking and insert the new PM
            $pmdm =& datamanager_init('PM', $vbulletin, ERRTYPE_ARRAY);

            $pmdm->set('fromuserid', $vbulletin->userinfo['userid']);
            $pmdm->set('fromusername', $vbulletin->userinfo['username']);
            $pmdm->setr('title', $pm['title']);
            $pmdm->setr('message', $pm['message']);
            $pmdm->set_recipients($pm['recipients'], $permissions);
            $pmdm->set('dateline', TIMENOW);

            // everything's good!
            $pmdm->save();
        }

        if ($formemail == "1")
        {
            require_once(DIR . '/includes/class_bbcode_alt.php');
            $plaintext_parser =& new vB_BbCodeParser_PlainText($vbulletin, fetch_tag_list());
            $plaintext_parser->set_parsing_language($touserinfo['languageid']);
            $formsend = $plaintext_parser->parse($formsend);

            $emails = explode(';', $formemailaddress);
            foreach ($emails AS $email)
            {
                vbmail($email, $posttitle, $formsend);
            }
        }

        if ($redirectoption == "1")
        {
            $vbulletin->url = 'showthread.php?' . $vbulletin->session->vars['sessionurl'] . "p=$newpost[postid]";
            eval(print_standard_redirect('redirect_postthanks'));
            exit();
        }
        if ($redirectoption == "2")
        {
            $vbulletin->url = 'showthread.php?' . $vbulletin->session->vars['sessionurl'] . "t=$newpost[threadid]";
            eval(print_standard_redirect('redirect_postthanks'));
            exit();
        }
        if ($redirectoption == "3")
        {
            $vbulletin->url = 'forumdisplay.php?' . $vbulletin->session->vars['sessionurl'] . "f=$foruminfo[forumid]";
            eval(print_standard_redirect('redirect_postthanks'));
            exit();
        }
        if ($redirectoption == "4")
        {
            $vbulletin->url = 'editpost.php?do=editpost&' . $vbulletin->session->vars['sessionurl'] . "p=$newpost[postid]";
            eval(print_standard_redirect('redirect_postthanks'));
            exit();
        }
        eval('print_output("' . fetch_template('STANDARD_ERROR') . '");');
        exit();
    }
    else
    {
          require_once('./includes/class_bbcode.php');
        $parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());
        $preview = $parser->do_parse($formsend);

        $_REQUEST['action'] = 'form';
    }
}

if ($_REQUEST['action'] == 'form')
{
    if (($formforum OR $formreply) AND $allow_attachments)
    {
        if ($formforum AND $formreply)
        {
            $forumid = $formforumid;
        }
        else if ($formreply)
        {
            $threadid = $formreplythreadid;
            $threadinfo = verify_id('thread', $threadid, 0, 1);
            $forumid = $threadinfo[forumid];
        }
        else
        {
            $forumid = $formforumid;
        }

        $forumperms = fetch_permissions($forumid);

        // get attachment options
        require_once(DIR . '/includes/functions_file.php');
        $inimaxattach = fetch_max_upload_size();

        $maxattachsize = vb_number_format($inimaxattach, 1, true);
        $attachcount = 0;
        $attach_editor = array();
        $attachment_js = '';

        if ($forumperms & $vbulletin->bf_ugp_forumpermissions['canpostattachment'] AND $vbulletin->userinfo['userid'] AND !empty($vbulletin->userinfo['attachmentextensions']))
        {
            if (!$posthash OR !$poststarttime)
            {
                $poststarttime = TIMENOW;
                $posthash = md5($poststarttime . $vbulletin->userinfo['userid'] . $vbulletin->userinfo['salt']);
            }
            else
            {
                if (empty($postattach))
                {
                    $currentattaches = $db->query_read("
                        SELECT dateline, filename, filesize, attachmentid
                        FROM " . TABLE_PREFIX . "attachment
                        WHERE posthash = '" . $db->escape_string($posthash) . "'
                            AND userid = " . $vbulletin->userinfo['userid']
                    );

                    while ($attach = $db->fetch_array($currentattaches))
                    {
                        $postattach["$attach[attachmentid]"] = $attach;
                    }
                }

                if (!empty($postattach))
                {
                    foreach($postattach AS $attachmentid => $attach)
                    {
                        $attach['extension'] = strtolower(file_extension($attach['filename']));
                        $attach['filename'] = htmlspecialchars_uni($attach['filename']);
                        $attach['filesize'] = vb_number_format($attach['filesize'], 1, true);
                            $attach['imgpath'] = "$stylevar[imgdir_attach]/$attach[extension].gif";
                        $show['attachmentlist'] = true;
                        eval('$attachments .= "' . fetch_template('newpost_attachmentbit') . '";');

                        $attachment_js .= construct_attachment_add_js($attachmentid, $attach['filename'], $attach['filesize'], $attach['extension']);

                        $attach_editor["$attachmentid"] = $attach['filename'];
                    }
                }
            }

            if ($threadid)
            {
                $attachurl = "t=$threadid";
            }
            else
            {
                $attachurl = "f=$forumid";            
            }
            $newpost_attachmentbit = prepare_newpost_attachmentbit();
            eval('$attachmentoption = "' . fetch_template('newpost_attachment') . '";');

            if ($threadid)
            {
                $attach_editor['hash'] = $threadid;
                $attach_editor['url'] = "newattachment.php?$session[sessionurl]t=$threadid&amp;poststarttime=$poststarttime&amp;posthash=$posthash";
            }
            else
            {
                $attach_editor['hash'] = $forumid;
                $attach_editor['url'] = "newattachment.php?$session[sessionurl]f=$forumid&amp;poststarttime=$poststarttime&amp;posthash=$posthash";        
            }
        }
        else
        {
            $attachmentoption = '';
        }
    }
    else
    {
        $attachmentoption = '';
    }

    // set message box width to usercp size
    $stylevar['messagewidth'] = $stylevar['messagewidth_usercp'];
    $editorid = construct_edit_toolbar($vbtextanswer);

    eval('print_output("' . fetch_template("$maintemplate") . '");');
}
}

Basically, when I click on Preview (Anteprima Richiesta), it reload the page but the input text for "Inserisci qui il Titolo del tuo sito: " and the choice of the radio buttons disappear. So I have to write it again and select it again. I can’t understand the reason. Can you please help me? This is done via vBulletin.

I don’t know vBulletin, but is this a typo?

Inserisci qui il Titolo del tuo sito: <input type="text" size="30" value="$risposta_titolowdwd" name="risposta_titolowd" />

Specifically the varname in the value field has an extra “wd” on the end compared to the name field, and the first few times I saw it in the php code.

1 Like

Yes, thank you so much! Now I solved with that! My error, excuse me! :smiley:

Another problem: when I click on the radio button “yes” and I reload, then it is still checked. If I click on the radio button “no”, when I click on Preview (Anteprima Richiesta) it is no more checked and I have to click on it again.

Also, when I first load the page it is already checked (no), and it shouldn’t.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.