Post subject: Sending form information to the same page php
I have a simple form with some variables carrying information from the input fields. After submitting the form, instead of sending or redirecting the user to a new page I want him to come to the same page where the form is, with form information processed already. How do I write the code in php so that the post methid refers to the php self page? _________________ “You might say reality is the result of complex negotiations between the observer and the observed. But that is simply a point of view…”
Digital Bangladesh
Fri Jul 16, 04 5:48 am
quantum Site Admin
Joined: 07 Mar 2004 Posts: 1048
Location: Dhaka, Bangladesh
Post subject:
Sorry emm, I did not notice this thread. Posting to the same page is as easy as giving the post url as the same page's name in the form action! Like this:
Code:
<form action="thispage.php" method=post>
Now what you can do after that is make a few switch statement that would check if certain variables are empty or not. If this then do that. If this then do the other thing. Like that. Hope that helps.
For instance here is a complete code for a php ftp program that does everything from a single page of script. Very kool. Check the php code and how it uses switches to evaluate what action to take everytime the form is posted to the same php page.
Code:
<?php
/* Configuration Options */
$phpftp_host=" ";
$phpftp_version="2.2";
/* Comment this out if you don't want the version footer */
$show_version_footer=0;
/* How large a file will you accept? You may also need to edit your
php.ini file and change upload_max_filesize appropriately */
$max_file_size="5000";
/* The temporary directory $phpftp_tmpdir must exist and be writable
by your web server.
Hint: mkdir /var/tmp/xfers && chmod 1777 /var/tmp/xfers */
/* We enclose the top and bottom in functions because sometimes
we might not send them (ie, in a file-download situation) */
function phpftp_top() {
global $phpftp_version;
?>
<!-- function phpftp_top -->
<html>
<head>
<title>PHP FTP Client <?php echo $phpftp_version; ?></title>
</head>
<body bgcolor="#ffffff">
<?php
}
function phpftp_bottom() {
global $phpftp_version;
global $show_version_footer;
?>
<!-- function phpftp_bottom -->
<?php
if (isset($show_version_footer)) {
?>
<?php
}
?>
</body>
</html>
<?php
}
/* This is the form used for initially collecting username/passwd */
/* This function does not return TRUE/FALSE - it returns the value of
$ftp, the current FTP stream. */
function phpftp_connect($phpftp_user,$phpftp_passwd) {
global $phpftp_host;
$ftp = ftp_connect($phpftp_host);
if ($ftp) {
if (ftp_login($ftp,$phpftp_user,urldecode($phpftp_passwd))) {
return $ftp;
}
}
}
function phpftp_list($phpftp_user,$phpftp_passwd,$phpftp_dir) {
global $phpftp_host;
phpftp_top();
?>
<!-- function phpftp_list -->
<?php
$ftp = @phpftp_connect($phpftp_user,$phpftp_passwd);
if (!$ftp) {
?>
<strong>FTP login failed!</strong>
<a href="ftp.php">Start over?</a>
<?php
phpftp_bottom();
} else {
if (!$phpftp_dir) {
$phpftp_dir=ftp_pwd($ftp);
}
if (!@ftp_chdir($ftp,$phpftp_dir)) {
?>
<font color="#ff0000"><strong>Can't enter that directory!</strong></font><p><p>
<?php
$phpftp_dir=ftp_pwd($ftp);
}
echo "<strong>Current host:</strong> " . $phpftp_host . "<br>\n";
echo "<strong>Current directory:</strong> " . $phpftp_dir . "<br>\n";
if ($phpftp_dir == "/") {
$phpftp_dir="";
}
switch($function) {
case "dir";
phpftp_list($phpftp_user,$phpftp_passwd,$phpftp_dir);
break;
case "cd";
phpftp_cd($phpftp_user,$phpftp_passwd,$phpftp_dir,$select_directory);
break;
case "get";
phpftp_get($phpftp_user,$phpftp_passwd,$phpftp_dir,$select_file);
break;
case "put";
phpftp_put($phpftp_user,$phpftp_passwd,$phpftp_dir,$userfile,$userfile_name);
break;
case "mkdir";
phpftp_mkdir($phpftp_user,$phpftp_passwd,$phpftp_dir,$new_dir);
break;
case "";
phpftp_login();
break;
}
Post subject: Submitting to the same page with php..thanks.
Hey that's great man. The example really did it for me. _________________ “You might say reality is the result of complex negotiations between the observer and the observed. But that is simply a point of view…”
Digital Bangladesh