Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Closed Thread
page reload on form submit
Old 04-17-2008, 04:53 PM page reload on form submit
Novice Talker

Posts: 10
Trades: 0
hey

i'm wanting my php page to reload when the user submits the form (action ="$PHP_SELF") on it but i'm not sure how to go about that

i'm looking for some sort of reload self

could anyone help with this please?
namaah is offline
View Public Profile
 
 
Register now for full access!
Old 04-17-2008, 05:06 PM Re: page reload on form submit
Extreme Talker

Posts: 177
Trades: 0
well, one thing you can do is have the form submit to an arbitrary php document, and based on the inputs and all the forms are complete, you can set the header to the required page.

For the message system I have setup, teh action is action=r.php?tankien=6, and theres a switch in there for $_REQUEST['tankien'] and if the form is filled out correctly, it sets $_SESSION['header'] to message.php, otherwise it goes back to message.php?opt=4, and in r.php, it also has a $responseMsg that lets you know what happened.

Heres the code, kinda.

PHP Code:
echo '
    <head>
    <meta http-equiv="refresh" content="3; url=' 
$_SESSION['header'] . '"/>
    </head>'

and below that it has

PHP Code:
echo '
<body>
<table height="50%" align="center">
<tr>
<td valign="bottom">'
;
echo 
$responseMsg;
echo 
'<br /><br /> Please wait while we transfer you.... <br /><br />';
echo 
'<a href="' $_SESSION['header'] . '">(Or click here if you wish not to wait)</a>';
unset(
$_SESSION['header']); 
I feel like I'm making it sound confusing...but hopefully you understand what I did, let me know if you need further clarification.
kbfirebreather is offline
View Public Profile
 
Old 04-17-2008, 08:18 PM Re: page reload on form submit
Novice Talker

Posts: 10
Trades: 0
thanks but the form needs to submit to its self , i'm not sure if i understand what you ment and i dont know how to use that so that the form will submit to itself then load a page (i'm new to php) loading another page first and redirecting back is fine tho
namaah is offline
View Public Profile
 
Old 04-17-2008, 08:51 PM Re: page reload on form submit
Extreme Talker

Posts: 177
Trades: 0
Well you could put all the code into the self php document.

If the php page the form is on is settings.php, just have action="settings.php"
kbfirebreather is offline
View Public Profile
 
Old 04-17-2008, 09:59 PM Re: page reload on form submit
Novice Talker

Posts: 10
Trades: 0
i think i'm doing something wrong here , the page just keeps rereshing itself every 3 seconds and doesn't reload at all

Last edited by namaah; 04-17-2008 at 10:16 PM..
namaah is offline
View Public Profile
 
Old 04-17-2008, 10:27 PM Re: page reload on form submit
Extreme Talker

Posts: 177
Trades: 0
If you're using the r.php method, make sure you set $_SESSION['header'] to the correct page, or else it will be NULL and the
PHP Code:
<meta http-equiv="refresh" content="3; url=' . $_SESSION['header'] . '"/> 
will just keep refreshing r.php cause there is no url set.


also: make sure you have session_start(); at the top of the page, before ANYTHING. this enables session variables to be used.
kbfirebreather is offline
View Public Profile
 
Old 04-17-2008, 11:08 PM Re: page reload on form submit
Novice Talker

Posts: 10
Trades: 0
sorry but i'm just not getting this at all :/

this is what i have
PHP Code:
<?php
session_start
();
//not sure if this is what you ment by setting the
// $_SESSION['header'] to the correct page but it's 
//the same with or without it
$_SESSION['header'] = "page.php";
echo 
'<head><meta http-equiv="refresh" content="3; url=' $_SESSION['header'] . '"/></head>';
echo 
'<body>'
//forms , php and sql stuff
 
unset($_SESSION['header']);
i cant seem to find a site that explains this sessions thing clearly

this is reloading the page when it submits now but it is still refreshing every 3 seconds aswell. am i using it right?
namaah is offline
View Public Profile
 
Old 04-17-2008, 11:30 PM Re: page reload on form submit
Extreme Talker

Posts: 177
Trades: 0
heres a complete example.

heres checkActivit.php which is included in r.php (last code segment)
PHP Code:
<?php

include("connect.php");

if(
$_REQUEST['password1']==NULL || $_REQUEST['password2']==NULL || ($_REQUEST['password1'] != $_REQUEST['password2']))
{
    
$_SESSION['header'] = 'a.php?p=' $_SESSION['password'];
    
$responseMsg "The passwords you entered did not match, please try again.";
}
else
{
    
//echo 'user: ' . $_SESSION['newUser'];
    
mysql_query("UPDATE users SET Password = '$_REQUEST[password1]' WHERE Username = '$_SESSION[newUser]'");
    
    
$responseMsg "Your account should be successfully upated, go ahead and try to log in. If you experience any errors, let me know *****.";
    
    
$_SESSION['header'] = "index.php";
    
    unset(
$_SESSION['password']);
    
$user mysql_fetch_array(mysql_query("SELECT * FROM users WHERE Username = '$_SESSION[newUser]'"));
    
$_SESSION['newUser'] = $user['Username'];
}

?>
heres my form
PHP Code:
echo '<form action="r.php?tankien=2" method=post> <br />';
    echo 
'Please set a password. <br />';
    echo 
'Username: <input type="text" name="user" value="' $userPass['Username'] . '" disabled> <br />';
    echo 
'New password: <input type="password" name="password1"> <br />
          Confirm Password: <input type="password" name="password2"> <br />'
;
    echo 
'<input type="submit" value="Activate me!"> </form>';
    echo 
'</td> </tr> </table> </body> </html>'
which submits to r.php, and includes checkActivit.php which is the first php segment. So, the form calls r.php, r.php includes checkActivit.php which sets the session variables....once the switch is done in r.php, it continutes to the rest below, and uses the session variables and the responseMsg to display what happened and forward to the correct page



r.php:
PHP Code:
<?php

session_start
();

?>

<html>
<?php
//$responseMsg = $_SESSION['message'];
switch($_REQUEST['tankien'])
{
    case 
0:
    
// CHECKS TO SEE IF PASSWORD WAS CHANGED, OR THE PIC/EMAIL WAS CHANGED
    
include("checkSettingsChanged.php");
    break;

    case 
1:
    
//CHECKS TO VALIDATE NEW EMPLOYEE INFORMATION, AND ADD IT TO THE DATABASE
    
include("checkAddEmployee.php");
    break;
    
    case 
2:
    
//CHECKS TO VALIDATE THE PASSWORD FOR ACTIVATING THE NEW ACCOUNT
    
include("checkActivit.php");
    break;
    case 
3:
    include(
"sendPassword.php");
    break;
    case 
4:
    include(
"deleteMessages.php");
    break;
    case 
5:
    include(
"checkEditEmployee.php");
    break;
    case 
6:
    
$_SESSION['message'] = trim($_POST['message']);
    
$_SESSION['subject'] = trim($_POST['subj']);
    
//VALIDATES MESSAGES BEING SENT
    
include("e-send.php");
    break;
    
}





echo 
'
    <head>
    <meta http-equiv="refresh" content="3; url=' 
$_SESSION['header'] . '"/>
    </head>'
;
    
    

echo 
'
<body>
<table height="50%" align="center">
<tr>
<td valign="bottom">'
;
echo 
$responseMsg;
echo 
'<br /><br /> Please wait while we transfer you.... <br /><br />';
echo 
'<a href="' $_SESSION['header'] . '">(Or click here if you wish not to wait)</a>';
unset(
$_SESSION['header']);
?>
</td>
</tr>
</body>

</html>
kbfirebreather is offline
View Public Profile
 
Closed Thread     « Reply to page reload on form submit
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.26981 seconds with 12 queries