Passing variables from one page to another, can do?

Discuss phpwcms here, please do not post support requests, bug reports, or feature requests! Non-phpwcms questions, discussion goes in General Chat!
Post Reply
deanloh
Posts: 99
Joined: Sat 12. Feb 2005, 05:31
Location: Singapore
Contact:

Passing variables from one page to another, can do?

Post by deanloh »

Someone might have answered to this before, please point me to the right directions if you see the answer somewhere.

Scenario:
On one page I have a simple form, a user enters basic information such as name, email address.

There are two buttons to click, one is "Submit", which will submit the basic information when clicked.

The other button is "Advanced", click on it a page will load, displaying a more complicated form, that has name, email address, and much other information, menus, etc.

Question:
How do I make sure the name and email address is passed on from the previous page? Which mean when the complicated form is loaded, the name and email address should already be filled in. With standard PHP page, that can be easily done by passing the variables over, but somehow it won't work for phpwcms.

I have the feeling this should be simple, for same reason I feel stupid not being able to figure it out (blame it on coffee overdose).

So please help.
mazze
Posts: 21
Joined: Thu 3. Mar 2005, 10:14
Location: zug/switzerland
Contact:

Post by mazze »

Be sure that you do not use the url alias function (index.php?mysite). use the URL that is based on numbers

in one of my projects i had the same requirement:

index.php?id=240,0,0,1,0,0&xid=1

on the following page i could build the IF query for the variable XID
deanloh
Posts: 99
Joined: Sat 12. Feb 2005, 05:31
Location: Singapore
Contact:

Post by deanloh »

Thanks for responding mazze

Have tried that, not working.

Basically, I have the following codes in page 1 (index.php?id=11,19,0,0,1,0):

Code: Select all

<form name="form1" id="form1" method="POST" action="index.php?id=11,20,0,0,1,0">
Name: 
<input type="text" name="name" />
<br />
Email: 
<input type="text" name="email" /><br />
<br />
<input type="submit" name="Submit" value="Submit" />
</form>
Then, I have this in the receiving page (index.php?id=11,20,0,0,1,0):

Code: Select all

[PHP]
if (isset($name)) {
echo $name;
}
[/PHP]
If I filled something in the name field of page one, upon submit, the $name var should be echoed in second page. But its not happening, and I wonder why.
deanloh
Posts: 99
Joined: Sat 12. Feb 2005, 05:31
Location: Singapore
Contact:

Post by deanloh »

I realised I dont get much replies on most of the questions I asked so far, either my questions are too tough or they are simply not important.

It may be fine when I'm using phpwcms for personal site when problems like this can easily be ignored. But when it comes to using phpwcms for corporate sites, delay like this can sometimes be very destructive.

We are not even talking about bugs. It's sheer question of usability. I can appreciate the fact this script is given free that I should just be happy with the way it is. But like it or not, at this rate, phpwcms will not be able to go far and it will forever remains as a "personal hobby project".

Forgive my bitching, I just hope you all can understand: I wouldnt bother complaining about something if I don't care about it. Cross my heart, I hope to see phpwcms go really far! (I am already honored to be one of the users).
brans

Post by brans »

try to use $POST['name'] instead of $name, shouldn't this do ?

Maybe you could also use sessions vars, have a look at the css switch mod hack at our dev forum --...--, where you can see how oliver uses session vars to pass them over to another page. I have actually noticed a similar problem some weeks back.
User avatar
Kosse
Posts: 1066
Joined: Thu 9. Sep 2004, 12:08
Location: Brussels, Belgium
Contact:

Post by Kosse »

Deanloh, I feel just like you, honored to contribute by using this cms (best so far I've seen)

Anyway, I think brans's right, in dev 1.2.1 you can pass sessions through POST.

Here's the CSS code snippet, normally you put it in the header
[PHP]
if(!empty($_POST['cssvalue1'])) {
$_SESSION['CSS'] = 1;
} elseif(!empty($_POST['cssvalue2'])) {
$_SESSION['CSS'] = 2;
}
if(!empty($_SESSION['CSS'])) {
switch($_SESSION['CSS']) {
case 1: echo '<!-- YOUR CSS CODE FOR SELECTION 1 -->'; break;
case 2: echo '<!-- YOUR CSS CODE FOR SELECTION 2 -->'; break;
case 0: unset($_SESSION['CSS']); break;
}
}
[/PHP]
I guess you would have to change $_SESSION['CSS'] with your own vars, like i.e. $_SESSION['FORM_NAME']
then put the code snippet in your advanced form

something like

Code: Select all

[PHP]
if(!empty($_POST['advanced'])) {
  $_SESSION['advanced'] = 1;
}
elseif(!empty($_POST['normal'])) {
  $_SESSION['normal'] = 2;
}
if(!empty($_SESSION['advanced'])) {
  switch($_SESSION['advanced']) {
    case 1: echo '$name'; break;
    case 2: echo ' '; break;
    case 0: unset($_SESSION['advanced']); break;
  }
}
[/PHP]
maybe this is too complicated (or wrong) I don't know (not a php specialist), maybe it's one of the possible ways to get the answer.


Good luck
User avatar
Oliver Georgi
Site Admin
Posts: 9919
Joined: Fri 3. Oct 2003, 22:22
Contact:

Post by Oliver Georgi »

OK - here is a possible solution - such functionality is hard to simulate based on phpwcms.

Here is a script that can be used by using {PHP:path_to_script/myscript.php}

Code: Select all

<?php

// do check here

// new function for sending email from any custom script
// based on phpwcms' settings
// function sendEmail($recipient='', $subject='email', $body='', $attach=array(), $isHTML=0, $from='', $fromName='', $sender='')

$form_name = '';
$form_email = '';
$ADVANCED = isset($_POST['formStatus']) ? intval($_POST['formStatus']) : 0;
$ERR = '';
$_sendEmail[0] = false; //default email send status array info

if(isset($_POST['formStatus'])) {
	
	switch($ADVANCED) {
	
		case 0:		// basic form
					if(!empty($_POST['name'])) {
						$form_name = remove_unsecure_rptags($_POST['name']);
					} else {
						$ERR .= '<p>No name</p>';
					}
					if(!empty($_POST['email']) && is_valid_email($_POST['email'])) {
						$form_email = remove_unsecure_rptags($_POST['name']);
					} else {
						$ERR .= '<p>Check email</p>';
					}
					if(isset($_POST['submitAdvanced'])) {
						$ADVANCED = 1;
					}
					if(empty($ERR) && $ADVANCED == 0) {
						//send email function
						//$_sendEmail = sendEmail('oliver@phpwcms.de', 'My subject', 'build a body', array(), 0, 'info@phpwcms.de');
					}
			
					break;
		
		case 1:		// advanced form
		
					// ...do advanced form check here
					break;
		
		// ...and so on
	
	
	}
}


if(!$_sendEmail[0] && $ADVANCED == 0) {

		//index.php?<?=$GLOBALS['cache_query_string']
?>
<form name="form1" method="post" action="">
<?=$ERR ?>
<p>Simple Form:</p>
<p>Name: <input name="name" type="text" id="name" value=""></p>
<p>Email: <input name="email" type="text" id="email"></p>
<p><input name="submitBasic" type="submit" id="submitBasic" value="Send Basic">&nbsp;&nbsp;<input name="submitAdvanced" type="submit" id="submitAdvanced" value="Send Advanced"><input name="formStatus" type="hidden" id="formStatus" value="0"></p>
</form>
<?php
} elseif($_sendEmail[0] && $ADVANCED == 0) {
	
	echo 'basic form success';

}

/////////////////////////////////////////////////////////////////////////////


if(!$_sendEmail[0] && $ADVANCED == 1) {
?>
<form name="form1" method="post" action="">
<?=$ERR ?>
<p>Advanced Form:</p>
<p>Name: <input name="name" type="text" id="name" value="<?=$form_name?>"></p>
<p>Email: <input name="email" type="text" id="email" value="<?=$form_email?>"></p>
<p>Message: <textarea name="email" cols="50" rows="10" id="email"></textarea>
</p>
<p><input name="submit" type="submit" id="submit" value="Send">
<input name="formStatus" type="hidden" id="formStatus" value="1"></p>
</form>
<?php
} elseif($_sendEmail[0] && $ADVANCED == 1) {
	
	echo 'advanced form success';

}


?>
There is an additional function too (maybe) not available yet and not tested ;-) - so try and maybe use other functionality for sending

Code: Select all

function sendEmail($recipient='', $subject='email', $body='', $attach=array(), $isHTML=0, $from='', $fromName='', $sender='') {
	// used to send a standardized email message
	// based on phpwcms setting
	
	$mailInfo = array(0 => false, 1 => '');
	$sendTo = array();
	if(empty($from)) {
		$from = $GLOBALS['phpwcms']['SMTP_FROM_NAME'];
	}
	if(empty($sender)) {
		$sender = $from;
	}
	if(empty($fromName)) {
		$fromName = $GLOBALS['phpwcms']['SMTP_FROM_NAME'];
	}
	
	$recipient = str_replace(' ', '', trim($recipient));
	$recipient = str_replace(',', ';', $recipient);
	$recipient = str_replace(' ', '', $recipient);
	$recipient = explode(';', $recipient);
	if(is_array($recipient) && count($recipient)) {
		foreach($recipient as $value) {
			if(is_valid_email($value)) {
				$sendTo[] = $value;
			}
		}
	}
	
	if(count($sendTo)) {
		$mail = new PHPMailer();
		$mail->Mailer 			= $GLOBALS['phpwcms']['SMTP_MAILER'];
		$mail->Host 			= $GLOBALS['phpwcms']['SMTP_HOST'];
		$mail->Port 			= $GLOBALS['phpwcms']['SMTP_PORT'];
		if($GLOBALS['phpwcms']['SMTP_AUTH']) {
			$mail->SMTPAuth 	= 1;
			$mail->Username 	= $GLOBALS['phpwcms']['SMTP_USER'];
			$mail->Password 	= $GLOBALS['phpwcms']['SMTP_PASS'];
		}
		$mail->CharSet	 		= $GLOBALS['phpwcms']["charset"];
		$mail->IsHTML($isHTML);
		$mail->Subject			= $subject;
		$mail->Body 			= $body;
		if(!$mail->SetLanguage($GLOBALS['phpwcms']['default_lang'])) {
			$mail->SetLanguage('en');
		}
		$mail->From 		= $from;
		$mail->FromName		= $fromName;
		$mail->Sender	 	= $sender;

		$mail->AddAddress($sendTo[0]);
		unset($sendTo[0]);
		if(is_array($sendTo) && count($sendTo)) {
			foreach($sendTo as $value) {
				$mail->AddBCC($value);
			}
		}
		
		if(is_array($attach) && count($attach)) {
			foreach($attach as $attach_file) {
				$mail->AddAttachment($attach_file);
			}
		}
	
		if(!$mail->Send()) {
			$mailInfo[0]  = false;
			$mailInfo[1]  = $mail->ErrorInfo;
		} else {
			$mailInfo[0]  = true;
		}
		unset($mail);
		
	} else {
		$mailInfo[0]  = false;
		$mailInfo[1]  = 0; //means no recipient
	}

	return $mailInfo;
}
NEVER forget to use remove_unsecure_rptags() when recieving strings from POST or GET vars which maybe displayed in rendered result again.

Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
Post Reply