General Community > Scripting Help
passing form variables to a function
jami:
having this piece of crap code in a function:
--- Code: ---echo '<table width="100%" border="0" cellspacing="1" cellpadding="5" bgcolor="#6394bd">
<tr><td class="titlebg"><strong>· Inserimento Quiz</strong>
</td>
</tr>
<tr>
<td valign="top" class="windowbg2"> <form method="post" action="'.$boardurl.'?action=quizc">
<p align="center"><b>Nome del Quiz</b></p>
<p align="center">
<input name="name" type="text" size="70" />
</p>
<p align="center"><b>Autore</b></p><input type="hidden" name="creator" value="'.$username.'" />
<p align="center"><a href="$boardurl/index.php?action=quizd;nome='.$username.'">'.$username.'</a></p>
<p align="center"><b>Aggiunto il</b></p><input type="hidden" name="inserimento" value="'.gmstrftime("%d %B %Y, %I:%M:%S", time()+$timeoffset*3600).'" />
<p align="center">'.gmstrftime("%d %B %Y, %I:%M:%S", time()+$timeoffset*3600).'</p>
<p align="center"><b>Descrizione del Quiz</b></p>
<p align="center">
<textarea name="description" cols="70" rows="8"></textarea>
</p>
<p align="center">
<input type="submit" name="Submit" value="Inserisci" />
</p>
</form></td>
</tr>
<tr>
<td bgcolor="#DEE7EF">
<img src="'.$imagesdir.'/quiz.gif" align="absmiddle"> <a href="'.$boardurl.'/index.php?action=quiz">Pagina Principale dei Quiz</a>
</td>
</tr>
</table>';
--- End code ---
how to pass the variables name, creator, inserimento and description ?
$title=$_GET['name']; or $title=$_POST['name']; or $_GLOBALS
I can't get it to work ... che somaro.
Aquilo:
function something(){
global $name, $creator, $inserimento, $description;
echo $name.$creator.$inserimento.$description;
}
make them global. declare them as global
Haase:
You should be able to get it to work just by using $_POST['name'], etc. in the code on the next page. I'm not sure why it's not working though...
But on another note (probably not related), you should probably give your form a name.
--- Code: ---<form method="post" name="the_form_name" action="'.$boardurl.'?action=quizc">
--- End code ---
Particulary if there is more than one form on the page.
jami:
I've resolved the problem writing 2 function:
in the the first function there's the form with input name="namevar" and as action the second function
in the second function there's no global var declared, only $_POST[namevar] passed to the insert query.
and it works ;).
add: I think code fontsize can be greater ( 9px?)
chris:
--- Quote from: jami on August 29, 2003, 12:54:45 PM ---in the second function there's no global var declared, only $_POST[namevar] passed to the insert query.
--- End quote ---
You're meaning addslashes($_POST[namevar]) is passed to the insert-query, right? Passing Variables without escaping ' and " would be stupid....
Navigation
[0] Message Index
[#] Next page
Go to full version