You are not logged in.

Announcement

Forum database was corrupt and an old backup was restored as temporary replacement. Registrations closed until the database is recovered. Please ask questions using the Contact form

#1 10-01-2014 20:01:00

roberto.cohen
Contributors
From: Brazil
Registered: 08-10-2013
Posts: 12
Website

Receiving parameters from POST in a subpage

Hi, friends.

I have a problem:

I can't get parameters from a POST form inside a subpage.

Do I have to do anything else?

If I refer the absolute URL in the action of form, the page receive the parameters with no problem.

But if the URL is simple like this: "#!/free_send.php", then I can't get the parameters.

I studied the contact.php, but it's very advanced in bundling of commands to me.

Regards,

Roberto
Come to messy Brasil, the 2014 world cup

Offline

#2 10-01-2014 23:51:11

chrismaliszewski
Contributors
From: Torun, Poland
Registered: 06-05-2013
Posts: 246
Website

Re: Receiving parameters from POST in a subpage

I'll tell you have one time I made it on this page.
I simply created normal form as

<form id="registration_form" action="pages/registration_proc.php?language=<?php echo $_SESSION['language'];?>" method="post">

Registration_proc.php was file which was doing all things around $_POST data (validation, saving files etc.). When everything was all right I used redirection function of PHP (header()) to go back to page I wanted and display information about what happened (success, failure, error etc.).
This is how I made it.

About your try.
Where do you put file which process data from form? Remember that if you use function set_include_path("../"); in PHP file you can use relative paths from catalogue where index.php is.
And 2nd thing - #!/free_send.php address looks strange to me. Did you mean #!/free_send maybe? Did you write in config/pages.php sth like

$pageTitles['your_page.php'] = "free_send.php";

or either

$pageTitles['your_page.php'] = "free_send";

If 2nd use #!/free_send in action and MAYBE it'll work.

Cheers. Good night to me smile.

Offline

#3 11-01-2014 21:03:55

Thomas
Administrator
Registered: 10-03-2013
Posts: 897

Re: Receiving parameters from POST in a subpage

You can't directly POST to subpages because of the transitions, or you need to capture it in the index file but that's really not recommend.

The easy way: put your form in an iframe and everything will work fine.

The little bit harder way; use jQuery AJAX forms (that's how the contact form example works)

Offline

#4 14-01-2014 18:59:14

roberto.cohen
Contributors
From: Brazil
Registered: 08-10-2013
Posts: 12
Website

Re: Receiving parameters from POST in a subpage

Well,

Thanks friends for tips.

I duplicated CONTACT.PHP and made my own version of another form.

Hugs from South Brazil,

Roberto

Offline

#5 30-04-2014 11:40:53

deci0
Contributors
Registered: 30-08-2013
Posts: 26

Re: Receiving parameters from POST in a subpage

Hi Thomas,

What do you mean by : "...put your form in an iframe..." ? could you give a example, please ?

I have a bit problem different : a connection with a MSSQL DB and a drop-down list populated with data from DB.

I would like use the POST method to pick data choosen in drop-down list and use it as variable in a SQL query to build a TABLE, in the same page or in another page.

But I always have an error message : "Notice: Undefined index: ... in ...php on line .."

I've try the GET method (just for test), and I could see that the data is taken (I see it as part of URL)... so, I would like to know if you or someone else could help me.

This is my FORM code :

<form method="POST" action="#!/test2">
<label>Sélectionnez :</label>
<select id="NoInv" name="mySelection" >
<?php
while($obj = odbc_fetch_object($result)){?>
<option value="<?php print htmlentities($obj->NoInv); ?>" selected=""><?php print htmlentities($obj->AppEnv); ?></option>
<?php } //end the loop 
?>
</select>
<input type="submit" value="Rechercher les composants">
</form>

AppEnv is the data I see in my drop-down list, and NoInv is the data I want to pick to put as variable in a SQL query.

Any help will be warmly apreciated. Thanks in advance.

deci0

Offline

#6 30-04-2014 14:20:33

chrismaliszewski
Contributors
From: Torun, Poland
Registered: 06-05-2013
Posts: 246
Website

Re: Receiving parameters from POST in a subpage

deci0, I'll put in your two cents' worth.

Perhaps when Thomas said "put your form in an iframe", he wanted to suggest to POST form in iframe to parent window or another iframe on page. There is also another way to work with iframes mentioned in book Professional JavaScript For Web Developers chapter 16 section Hidden Frames. You can read about it there.

About your problem: maybe problem is in wrong way of passing POST variables to another page. Where is original form (page name), to which page original form passes POST, how does query look like?
Check if POST variable is passed before doing query, because as you said if GET works, POST also should have and if it isn't, there is a problem with passing POST.

Offline

#7 30-04-2014 15:14:11

deci0
Contributors
Registered: 30-08-2013
Posts: 26

Re: Receiving parameters from POST in a subpage

Hi chris, and thank you very much for your kind help !

This is the code of my page : test1.php, referenced on pages.php as test1 :

<?php

include_once("sqltools.php");

// Connexion au serveur
$connection = odbc_connect("Driver={SQL Server};Server=$server;Database=$database;", $user, $password);
if ($connection == 0) {
echo "erreur de connexion au serveur";
      }

// Creation de la requete
$requete = "
SELECT      
            ass.NETWORK_IDENTIFIER + '    ---    ' + ass.E_ENVIRONNEMENT AS 'AppEnv'
			,ass.ASSET_TAG 'NoInv'
FROM 
			[EVO_DATA50004].[50004].AM_ASSET ass
            INNER JOIN [EVO_DATA50004].[50004].AM_CATALOG cat ON ass.CATALOG_ID = cat.CATALOG_ID
            INNER JOIN [EVO_DATA50004].[50004].AM_UN_CLASSIFICATION cla ON cla.UN_CLASSIFICATION_ID = cat.UN_CLASSIFICATION_ID
WHERE		
			cla.UN_CLASSIFICATION_FR LIKE 'Application' 
			AND ass.REMOVED_DATE IS NULL 
			AND (ass.[LAST_AUTOMATIC_DISCOVERY] BETWEEN DATEADD(DAY, -7, GETDATE()) AND ass.[LAST_AUTOMATIC_DISCOVERY])
ORDER BY	
			ass.NETWORK_IDENTIFIER ASC
			,CASE  
				WHEN ass.E_ENVIRONNEMENT = 'Bac à sable' THEN 1 
				WHEN ass.E_ENVIRONNEMENT = 'Bac à  sable' THEN 2
				WHEN ass.E_ENVIRONNEMENT = 'Développement' THEN 3
				WHEN ass.E_ENVIRONNEMENT = 'Intégration' THEN 4
				WHEN ass.E_ENVIRONNEMENT = 'Intégration 2' THEN 5
				WHEN ass.E_ENVIRONNEMENT = 'Test' THEN 6
				WHEN ass.E_ENVIRONNEMENT = 'Validation' THEN 7
				WHEN ass.E_ENVIRONNEMENT = 'Pré-Production' THEN 8
				WHEN ass.E_ENVIRONNEMENT = 'Production' THEN 9
				WHEN ass.E_ENVIRONNEMENT = 'Post-Production' THEN 10
				WHEN ass.E_ENVIRONNEMENT = 'Formation' THEN 11
				WHEN ass.E_ENVIRONNEMENT = 'Qualité' THEN 12
				WHEN ass.E_ENVIRONNEMENT = 'Vanilla' THEN 13
				WHEN ass.E_ENVIRONNEMENT = 'Inconnu' THEN 14
				WHEN ass.E_ENVIRONNEMENT = 'Indéfini' THEN 15
				ELSE 16 
			END
";

// Exécution de la requete
$result = odbc_exec($connection, $requete);

?>

<form method="POST" action="#!/test2">
<label>Sélectionnez:</label>
<select id="NoInv" name="mySelection" >
<?php
while($obj = odbc_fetch_object($result)){?>
<option value="<?php print htmlentities($obj->NoInv); ?>" selected=""><?php print htmlentities($obj->AppEnv); ?></option>
<?php } 
?>
</select>
<input type="submit" value="Rechercher les composants">
</form>

This is the code of my page : test2.php, referenced on pages.php as test2 :

<?php
echo $_POST['mySelection'];
?>

This is the error message showed on page test2 :
Notice: Undefined index: mySelection in ....\pages\test2.php on line 2

If I replace the POST method by GET on page test1, the URL of page test2 appears like this :
.../?mySelection=OI-FD900F988C1511E0A94E0050568F0078#!/test2

So, the variable mySelection has the correct value, but I can't catch it into page test2. It's crazy !!!

The actual code of page test2 it's just a test, because if I able to have a correct value, I'll be able to put it into my second SQL query to build my TABLE.

I tried to read (and understand) your recommendation : Hidden Frames. Unfortunately it's to dificult to my knowledge level... thanks anyway !

I hope these codes will be clear to everyone and someone could help me to find a solution. Thanks !

deci0

Offline

#8 30-04-2014 16:19:25

Thomas
Administrator
Registered: 10-03-2013
Posts: 897

Re: Receiving parameters from POST in a subpage

deci0 wrote:

So, the variable mySelection has the correct value, but I can't catch it into page test2. It's crazy !!!

It isn't crazy wink To show the page transitions, the template doesn't really work like a "normal" webpage. Normal posting just doesn't work because of the javascript.

Anyway. I've created a way to post to other pages but I really don't recommend it. But still, you can try and see if it's good enough for you.

Replace your js/main.js with:

https://www.dropbox.com/s/jgnp7g4xs00ci … 20post.zip

Then you can create a form on a subpage like this:

<script>
$("#thisForm").submit(function(){
	postForm = $(this).attr("id")
	window.location.hash = $(this).attr("action")
	return false
})
</script>

<form id="thisForm" method="POST" action="#!/accordions">
<input name="test" id="test" value ="this value"/>
<input type="submit" value="Rechercher les composants">
</form>

(note the javascript! )

and then you can get the post data on a subpage in the normal way :

<?php
if(isset($_POST['test'])){
	echo $_POST['test'];
}
?>

But I don't recommend it. Instead, try using the static pages plugin : http://metro-webdesign.info/forum/viewt … 2059#p2059
which allows you to do everything like a normal webpage (but without transitions smile )

Offline

#9 30-04-2014 16:37:30

deci0
Contributors
Registered: 30-08-2013
Posts: 26

Re: Receiving parameters from POST in a subpage

Thank you so much Thomas, I will try your solution tomorrow morning and will let you know the results.  wink

Have a nice evening !

deci0

Offline

#10 30-04-2014 17:41:15

chrismaliszewski
Contributors
From: Torun, Poland
Registered: 06-05-2013
Posts: 246
Website

Re: Receiving parameters from POST in a subpage

Or there is another way which I used in V3 (and another way which hit me now).

You need to POST form to page which you call as sth.php (not #!/sth !). Page sth.php process data, do what needs to be done (validation etc.), saves required data in $_SESSION, $_COOKIE, $_GLOBAL (somewhere, I used $_SESSION) and at the end redirect to proper page (this time from pages.php) i.e.

header("Location: #!/test2");

where you check if $_SESSION['sth_2'] is set or not, if yes - everything is all right, if not - do sth with it.

This way requires more files, is not so clear to read at the beginning because you need to jump from file to file to find what you want to do, but it doesn't require any changes in js/main.js.

Last possible way. Also uses SESSION variables but... "asynchronized" one - set by JavaScript. Read about them by Googling: javascript session variable. In such a way add onsubmit event to submit button which will first save needed SESSION variables (that is why "asynchronized" is in "", because it'll be synchronized action) and than submit form. Than in next website (test2.php, #!/test2) you can read them.

But 2nd way is only an idea - I haven't tried it.

Last edited by chrismaliszewski (30-04-2014 17:41:38)

Offline

#11 30-04-2014 18:02:52

Thomas
Administrator
Registered: 10-03-2013
Posts: 897

Re: Receiving parameters from POST in a subpage

Chris,

wouldn't it be easier then to just make a form like the contact form does? Post with to a back-end php, receive the data and process it with javascript.

Offline

#12 30-04-2014 18:11:35

chrismaliszewski
Contributors
From: Torun, Poland
Registered: 06-05-2013
Posts: 246
Website

Re: Receiving parameters from POST in a subpage

I haven't seen it. But if you say that it's easier, I trust you smile.

Offline

#13 01-05-2014 08:56:19

deci0
Contributors
Registered: 30-08-2013
Posts: 26

Re: Receiving parameters from POST in a subpage

Hi Thomas,

I replace the js/main.js file, and just tried to access my web site... big surprise : ALL my tiles has disappeared.

The navigation bar buttons seems to remain working, I can see the window navigation move, but with nothing under the navigation bar.

If I try to access directly to any specific page, the same result : nothing under the navigation bar.

An idea, about the source of problem ? Once again, I'm very thankful for your kind help.

Have a wonderful day,

deci0

Offline

#14 01-05-2014 10:39:59

Thomas
Administrator
Registered: 10-03-2013
Posts: 897

Re: Receiving parameters from POST in a subpage

If all tiles disappear, it means there's something wrong with the javascript.

Which version were you running? I modified the main.js file of the v4.3b1 version so you first need to upgrade to that one.

Offline

#15 01-05-2014 11:08:57

deci0
Contributors
Registered: 30-08-2013
Posts: 26

Re: Receiving parameters from POST in a subpage

It apears that my site is already on last version, as I can see in my index.php :

/* METRO UI TEMPLATE v4 beta 3.1

Offline

#16 01-05-2014 11:11:20

Thomas
Administrator
Registered: 10-03-2013
Posts: 897

Re: Receiving parameters from POST in a subpage

Hm strange. Please open the chrome console (F12) -> tab console and post the errors you get there.

Offline

#17 01-05-2014 11:37:43

deci0
Contributors
Registered: 30-08-2013
Posts: 26

Re: Receiving parameters from POST in a subpage

There are the errors, from Chrome console :

Uncaught TypeError: Cannot set property 'innerHTML' of null                 (index):179
Uncaught ReferenceError: chars is not defined                         VM226 main.js:150

This is part of code of my index.php (with line numbers)

172	<header>
173 		<div id="headerWrapper">
174			<div id="headerCenter">
175				<div id="headerTitles">
176					<h1><a href="<?php if($bot){echo "index.php";}?>#!"><?php echo $siteName?></h1></a>
177					<h2 align="right"><?php echo $siteDesc;?></h2>
178			    </div>
179			    <nav>
180	            	<?php
181					triggerEvent("mainNavBegin");
182			  		include_once("config/main-nav.php");
183					triggerEvent("mainNavEnd");
184					echo "<img align=\"right\" src=\"img/vdlogo.png\" alt=\"Logo du Canton de Vaud\" />"
185					?>
186				</nav>
187			</div>
188	    </div>
189	    <?php triggerEvent("headerEnd");?>
190	</header>

This is part of code of my NEW main.js (with line numbers)

149	$(window).hashchange(function(){
150		$hashed.get = chars(decodeURI(window.location.hash).replace("#!/","").replace("!/","").replace("#!","").replace("#","")).split("?");
151		$hashed.parts = $hashed.get[0].split("&");
152		$events.hashChangeBegin();
153		if($hashed.doRefresh){
154			if($hashed.parts[0] == ""){ // homepage with tiles
155				if($group.current == -1){ // no tiles shown
156					if($page.current == ""){
157						$show.tiles();
158					}else{
159						$show.prepareTiles();
160					}
161				}else{ // it must have been a tilegroup switch
162					if($hashed.parts.length>1){
163					}else if($group.current == 0){//we refresh the page
164						$show.prepareTiles();
165					}else{
166						$group.goTo(0);
167					}		
168				}
169			}else{ // page with content
170				if($page.current == "home"){ // homepage with tiles
171					$("#centerWrapper").fadeOut(hideSpeed,function(){
172						$show.page();
173					});
174				}else if($page.current != ""){ // other content page
175					$("#content").fadeOut(hideSpeed,function(){
176						$show.page();
177					});
178				}else{ // nothing loaded yet
179					$show.page();
180				}
181			}
182		}
183	
184		$events.hashChangeEnd();
185	});

Please, let me know if I made something wrong.

Thanks

deci0

Offline

#18 01-05-2014 13:21:27

Thomas
Administrator
Registered: 10-03-2013
Posts: 897

Re: Receiving parameters from POST in a subpage

Hmm, if you replace the main.js with one of the full package, it does work back again?

Offline

#19 01-05-2014 13:34:41

deci0
Contributors
Registered: 30-08-2013
Posts: 26

Re: Receiving parameters from POST in a subpage

You are absolutely right Thomas, I've tested with a v4b2 file and it doesn't work.

Sorry for the trouble and thanks for your patience with a simple beginner...   hmm

I will rebuild my site with a fresh v4b3.1 version, before ask help again. Then I can try to replace the main.js with the new you have sent me.

I'll keep you informed of results.

Have a nice afternoon.

deci0

Offline

#20 01-05-2014 13:38:01

Thomas
Administrator
Registered: 10-03-2013
Posts: 897

Re: Receiving parameters from POST in a subpage

Maybe it's a typo but you need the v4b3.1 file (downloadable on the forum here).
Anyway. I'd just backup your site and then apply the v4b3.1 upgrade package and probably everything work back again.

Else you can just copy all config files to a fresh copy.

Offline

#21 01-05-2014 17:21:28

deci0
Contributors
Registered: 30-08-2013
Posts: 26

Re: Receiving parameters from POST in a subpage

Thomas,

As Tina Turner would be said : YOU'RE  SIMPLY  THE  BEST !!

It works like expected.

Just another bug with these new sources, concerning the accents on the results of my SQL query... but I will find a solution.

Thanks again for your very professional help !

Have an excellent evening,

deci0

Offline

Board footer

Powered by FluxBB