Jump to content


Photo

PHP posting problem


Best Answer Gavski, 17 January 2014 - 12:16 PM

Thanks, that's great,

Ive found a similar but simpler solution -

 

if ($_SERVER["REQUEST_METHOD"] == "POST") { myfunction(); }

 

test whether a post has been made (in pre hypertext process.) ;)

 

thanks again.

Go to the full post


  • Please log in to reply
8 replies to this topic

#1 Gavski

Gavski

    Member

  • Members
  • PipPip
  • 13 posts

Posted 16 January 2014 - 05:47 PM

I have a form that contains a function. i want this function to be activated only when the user reposts the page to itself. (php_self).

 

ie. the user access the page and the function is hidden, the user then inputs data, repost the page and the function is activated.

 

I've tried flagging the function with a variable - $var = 0, then $var = 1 at the end of the page but $var just resets itself to 0 when the page is posted.

 

Sure this is simple but I just cant get it?

 

thanks



#2 ginerjm

ginerjm

    Advanced Member

  • Members
  • PipPipPip
  • 1,865 posts
  • LocationVoorheesville NY

Posted 16 January 2014 - 07:38 PM

You have a form with a function?  That's about the only thing I understood from your post.  And I don't believe it.  I'd love to see the code that implements this 'thing'.


JG

PS - If you're posting here you should be using:
        error_reporting(E_ALL | E_NOTICE);
        ini_set('display_errors', '1');

at the top of ALL php code while you develop it!


#3 KaiSheng

KaiSheng

    Advanced Member

  • Members
  • PipPipPip
  • 80 posts
  • LocationSinagpore
  • Age:20

Posted 16 January 2014 - 08:36 PM

it is php. pre hypertext process.

It won't work.



#4 Shayna23

Shayna23

    Newbie

  • New Members
  • Pip
  • 7 posts

Posted 16 January 2014 - 11:16 PM

Good question, I'd like to see the answer, too.


Edited by Shayna23, 16 January 2014 - 11:20 PM.


#5 Gavski

Gavski

    Member

  • Members
  • PipPip
  • 13 posts

Posted 17 January 2014 - 02:51 AM

Here's my form, it contains a function (really!). I want this function to work only after the form has been posted (not on initial loading). Here PHP reads the value of $token inside the function on loading (setsit to 1) and so executes the function when the page is loaded, there must be a way round this?

 

 

 

<?php

session_start();

$_SESSION['regName'] = $regValue; 

$token = 0;

//here's the function
function doThis()
{ echo "Do this Function";}


if ($token = 1)
{
doThis();
$token = 1;
}
echo $token;


?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" >
<input type="text" name="regName" value="">
<input type="submit">
</form>



#6 Gavski

Gavski

    Member

  • Members
  • PipPip
  • 13 posts

Posted 17 January 2014 - 02:58 AM

Sorry here it is again without the glaring error - 

 

<?php

session_start();

$_SESSION['regName'] = $regValue;

$token = 0;
//here's the function
function doThis()
{ echo "Do this Function";}


if ($token = 1)
{
doThis();
}

$token = 1;
echo $token;


?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" >
<input type="text" name="regName" value="">
<input type="submit">
</form>



#7 cyberRobot

cyberRobot

    Advanced Member

  • Gurus
  • 1,782 posts

Posted 17 January 2014 - 05:24 AM

You could use a hidden field to run the function. For example:

<?php
function doThis() {
     echo "Do this Function";
}
 
if(isset($_POST['runFunction'])) {
     doThis();
}
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" >
<input type="text" name="regName" value="">
<input type="hidden" name="runFunction" value="1">
<input type="submit">
</form>

Blogging about PHP and other web-related topics at ScorpBytes.com


#8 ginerjm

ginerjm

    Advanced Member

  • Members
  • PipPipPip
  • 1,865 posts
  • LocationVoorheesville NY

Posted 17 January 2014 - 09:11 AM

For future reference you have a "script with a function and a form".


JG

PS - If you're posting here you should be using:
        error_reporting(E_ALL | E_NOTICE);
        ini_set('display_errors', '1');

at the top of ALL php code while you develop it!


#9 Gavski

Gavski

    Member

  • Members
  • PipPip
  • 13 posts

Posted 17 January 2014 - 12:16 PM   Best Answer

Thanks, that's great,

Ive found a similar but simpler solution -

 

if ($_SERVER["REQUEST_METHOD"] == "POST") { myfunction(); }

 

test whether a post has been made (in pre hypertext process.) ;)

 

thanks again.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com