Reply to Re: Trying to have a state-machine one the page (newbie)

Your name:

Reply:


Posted by Hilarion on 10/10/33 11:25

>>> can't put this problem on line for now (too many .htaccess things).
>>> Anyhow my goal is to have a state machine on one page which from
>>> certain <form> results or any other working way will step into a new
>>> case called from that same page. Not sure to be 100% clear.
>>>
>>> Here is the sample code:
>>>
>>> // in the beginning of the php file I have
>>>
>>> switch ($_POST['action'])
>>> {
>>> case "update":
>>>
>>> /* Do some stuff...then */
>>>
>>> $url = $_SERVER['PHP_SELF'] ;
>>> echo "<form action=$action method='post'>\n" ;
>>> echo "<input type='HIDDEN' name='action' value='updated' />\n" ;
>>> echo "</form>\n" ;
>>> echo "<script> window.location.replace('$url') </script>\n";
>>
>>
>> This line above should probably be something like:
>>
>> echo "<script> window.location.replace('" . $action . "?action=updated')
>> </script>\n";
>>
>> And dump the <form> in this case (when you use location.replace, then
>> the form is not submitted, if it doesn't work, then user still can't
>> submit the form cause you did not provide the submit button).
>>
>>> break; // Probably useless ???
>>>
>>> // This is where I want to go from previous case
>>> case "updated":
>>> echo '<p>Updated</p>';
>>> ShowVar($_POST) ;
>>> break;
>>>
>>> default:
>>> break;
>>> }
>>>
>>> /* Do some other stuff...then */
>>
>>
>> The code below should be used only in case $_POST['action'] is not
>> set, so make it a "default" in your "switch".
>>
>>> echo "<tr><form action=$url method='post'>\n" ;
>>> echo "<td><input type='HIDDEN' name='action' value='update' />\n" ;
>>> echo "<input type='SUBMIT' name='update' value='Change!' /><</form>\n" ;
>>>
>>> /... this last submit work and go to update for sure.

> First thanks Hilarion for your input, I tried your submitted way and
> definitely goes towards this
> url="http://localhost/site1/menus/dm_menu_admin.php?action=updated" but
> even then I do not fall into my case switch as expected, and this is
> what I'm trying to achieve. Still investigating.

My fault. As you see "action" value "updated" is passed in URL, so
the GET method is used for it. You'll have to replace references to $_POST
with $_REQUEST or use some initialization code eg.:

<?php

if (isset($_POST['action']))
$action = $_POST['action'];
else if (isset($_GET['action']))
$action = $_GET['action'];

switch ($action)
{
case "update":
/* Do some stuff...then */
$url = $_SERVER['PHP_SELF'] ;
echo "<script>window.location.replace('" . $url . "?action=updated');</script>\n";
break;
case "updated":
echo '<p>Updated</p>';
ShowVar($action);
ShowVar($_GET);
ShowVar($_POST);
break;
default:
echo "<tr><form action=$url method='post'>\n" ;
echo "<td><input type='HIDDEN' name='action' value='update' />\n" ;
echo "<input type='SUBMIT' name='update' value='Change!' /><</form>\n" ;
break;
}
/* Do some other stuff...then */
?>

Notice that I used $action to store the passed value (you used $action
to fill "action" attribute value for <form> tag).


Hilarion

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация