Customizing SMF > SMF Coding Discussion
External HTML Form pass ($_GET/$_POST) to SMF PHP Page
phiberoptik:
Hi there! I'm attempting to create a new page through the Simple Machines administrator panel that will snag some variables from an HTML Form submission on a 3rd party php page.
I'm having trouble figuring out how to do this though, as I can't do:
http://moosevalley.net/index.php?page=page956?var1=This&var2=Works!
Basically I have the script done, and I need it to pass a few form variables.
Here's a testing script I put up, which proves it doesn't work as linked above.
<?php
$_POST['var1'];
$_GET['var2'];
echo "Your first variable is: " . $var1. "";
echo "<br />";
echo "Your second variable is: " . $var2. "";
?>
Xenocidius:
You don't seem to define $var1 or $var2 anywhere. How do you expect them to get values?
Try this:
--- Code: ---<?php
$var1 = $_GET['var1'];
$var2 = $_GET['var2'];
echo "Your first variable is: " . $var1;
echo "<br />";
echo "Your second variable is: " . $var2;
?>
--- End code ---
Also, the URL should be http://moosevalley.net/index.php?page=page956&var1=This&var2=Works.
phiberoptik:
I may have jumped the gun earlier, but let me see if I can get this solution working.
phiberoptik:
Maybe I'm just too tired... But here we go anyway.
This is the code that is on:
http://moosevalley.net/index.php?page=page2564
--- Code: ---<?php
require_once('SSI.php');
global $sourcedir, $user_info, $context, $smcFunc, $user_info;
$request = $smcFunc['db_query']('', '
SELECT value
FROM {db_prefix}themes
WHERE variable = \'cust_minecr\'
AND id_member = \'' . $user_info['id'] . '\''
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if( $row['value'] != null )
{
$ign = $row['value'];
}
}
$reason = $_POST['real_reason'];
$newreason = str_replace("%20"," ",$reason);
$time = date("d M, Y g:ia",$_POST['ban_time']);
require_once($sourcedir . '/Subs.php');
require_once($sourcedir .'/Subs-Post.php');
// CONFIGURATION SECTION
//send the application by email?
$enable_email=false;
// email address of recruitment staff member
$email_address='staff@moosevalley.net';
//post the application on forum?
$enable_post=true;
//board id to which the application should be posted
$board_id=29.0;
//the id of the this article
$this_article_id =page2564;
//article to be redirected when form is submitted
$thank_you_article_id =4;
//END OF CONFIGURATION SECTION
$show_form= 'true';
if (isset($_POST['submitted'])) {
// Handle the form
// Check required fields
$enroll_errors = array(); //Initialize error array
// Check for a name
if (empty($_POST['real_name']) ){
$enroll_errors[] = 'You forgot to enter your name.';
}
if (empty($enroll_errors)) { //Everything seems to be OK
$show_form='false';
$postbody = 'Unban Request made by ' . $context['user']['name'] .'
[table]
[tr][td][b]Your Name:[/b][/td][td]' . $_POST['real_name'] . '[/td][/tr]
[tr][td][b]Mod Name:[/b][/td][td]' . $_POST['mod_name'] . '[/td][/tr]
[tr][td][b]Ban Reason:[/b][/td][td]' . $_POST['ban_reason'] . '[/td][/tr]
------------------------------------------------------------------------------
[tr][td][b]Player Name:[/b][/td][td]' . $_GET['player_name'] . '[/td][/tr]
[tr][td][b]Mod Name:[/b][/td][td]' . $_GET['staff_name'] . '[/td][/tr]
[tr][td][b]Ban Reason:[/b][/td][td]' . str_replace("%20"," ",$_GET['real_reason']) . '[/td][/tr]
[tr][td][b]Time of Ban:[/b][/td][td]' . date("d M, Y g:ia",$_GET['ban_time']) . '[/td][/tr]
[tr][td][b]Ban Unique ID:[/b][/td][td]' . $_GET['ban_id'] . '[/td][/tr]
[table]
';
$msgOptions = array(
'id' => 0 ,
'subject' => '[Pending] Unban Request of ' . $context['user']['name'],
'body' => $postbody ,
'icon' => 'xx',
'smileys_enabled' => true,
'attachments' => array(),
);
$topicOptions = array(
'id' => 0 ,
'board' => $board_id,
'poll' => null,
'lock_mode' => null,
'sticky_mode' => null,
'mark_as_read' => false,
);
$posterOptions = array(
'id' => $context['user']['id'],
'name' => $context['user']['name'],
'email' => $user_info['email'],
'update_post_count' => true,
);
if ($enable_post)
createPost($msgOptions, $topicOptions, $posterOptions);
// Redirect to thank you page
header('Location: http://' . $_SERVER['HTTP_HOST'] .'/index.php?page=' . $thank_you_article_id);
} else {
// Redirect to error page
//header('Location: http://' . $_SERVER['HTTP_HOST'] . '/wow/index.php?page=' . $enroll_error_article_id );
echo '<h2 class="error">Error!</h2>';
echo '<p class="error">The following error(s) occured:
';
foreach ($enroll_errors as $msg) {
echo " - $msg
";
}
echo "<p>Please, correct all errors and try again.</p>" ;
}
}
//else { // Display the form
echo $reason;
echo $realreason;
echo $bantime;
echo $playername;
echo $staffname;
echo $banid;
echo "<br />";
echo '
<form action="index.php?page=' . $this_article_id . '" method="post">
<INPUT id="submitted" name="submitted" type="hidden" value="TRUE" />
<TABLE class = "bordercolor" cellSpacing="1" cellPadding="1" width="95%" border="0">
<TR class ="windowbg">
<TD width = "350px">* Your name :</TD>
<TD><INPUT id="real_name" name="real_name" type="text" value ="';
if (isset($_POST['real_name'])) echo $_POST['real_name'];
echo '" /></TD>
</TR>
<TR class ="windowbg">
<TD width = "350px">* Mod who banned you :</TD>
<TD><INPUT id="mod_name" name="mod_name" type="text" value ="';
if (isset($_POST['mod_name'])) echo $_POST['mod_name'];
echo '" /></TD>
</TR>
<TR class ="windowbg2">
<TD width = "350px">* Why you were banned :</TD>
<TD><TEXTAREA id="ban_reason" name="ban_reason" rows="4" cols="40" value ="';
if (isset($_POST['ban_reason'])) echo $_POST['ban_reason'];
echo '" ></' . 'TEXTAREA></TD>
</TR>
<TR class ="windowbg">
<TD colspan="2" align="center">
<INPUT type="submit" value="Submit">
<INPUT type="reset" value="Reset"></TD>
</TR>
</TABLE>
</form>
';
?>
--- End code ---
This is the page where I plan on getting the external $_GET's from.
http://play.moosevalley.net/mvbans.php
Clicking appeal forwards you to:
http://moosevalley.net/index.php?page=page2564&variable=blah
The issue I'm having is:
When I take those variables, and echo them below where the form is, they show up just fine, but as soon as I move them up higher where the user submitted post should go as if they were variables to be submitted into the post itself. Nothing happens.
If you need further information I'll respond in a few hours. I need sleep now though. I hope someone can help me figure out what's going wrong here. Thanks!
Xenocidius:
Well, here:
--- Code: ---<TD><INPUT id="real_name" name="real_name" type="text" value ="';
if (isset($_POST['real_name'])) echo $_POST['real_name'];
echo '" /></TD>
--- End code ---
You use $_POST['real_name'], when it should be $_GET['real_name'] or, to cover both bases, $_REQUEST['real_name'].
EDIT: And what the guy below me said.
Navigation
[0] Message Index
[#] Next page
Go to full version