Jump to content


Photo

Hidden variables?


  • Please log in to reply
8 replies to this topic

#1 Dr Ben Warne

Dr Ben Warne
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 16 October 2006 - 10:05 AM

I know i can do the below with more than just a hidden variable function, but as a few of you know i'm learning from scratch and want to learn a step at a time.

What i want is for this code

<html>
<head><title>Car Permit Application Form</title></head>
<body>
<h2>Car permit Application Form</h2>
<form action='carprocess.php' method='post'>
<input type='text' name='name' size=32 />Your name<br />
<input type='text' name='email' size=32 />Your Email Address<br />
<input type='text' name='address' size=32 />Your House Address<br />
Which of the following categories do you belong to ?<br/>
<select name='category'>
<option value='sr'>Student (Resident)</option>

<option value='snr'>Student (Non-Resident)</option>
<option value='str'>Staff (Resident)</option>
<option value='stnr'>Staff (Non-Resident)</option>
</select><br/>
<input type='submit' value='Submit Application' />
</form>
</body>
</html>

**Saved as carpark.html

AND

<html>
<head><title>Car Parking Application Status</title></head>
<body>
<h2>Car Parking Application Status</h2>
<?php
$status=array("sr"=>"Student (Resident)",
              "snr"=>"Student (Non-Resident)",
              "str"=>"Staff (Resident)",
              "stnr"=>"Staff (Non-Resident)");
$cat=$_POST[category];
echo "Thank you $_POST[name]. You are a $status[$cat] user.";
?>
</body>
</html>

**Saved a carprocess.php

What i want is a middle page that will ask for confirmation of the option value selected in html page, and then return the confirmation page it does currently.

Thanks for the help in advance, Dr Ben

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 16 October 2006 - 10:08 AM

Just send the user to another page to show there current selected items with a confirm button.

Then redirect them to pay.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 Dr Ben Warne

Dr Ben Warne
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 16 October 2006 - 10:11 AM

Just send the user to another page to show there current selected items with a confirm button.

Then redirect them to pay.


How do i do that?

Also how does it hold the variables for the 3rd page?

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 16 October 2006 - 10:20 AM

Please look up session ok

Remeber when using session that on all pages you must have
<?php
session_start();?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 Dr Ben Warne

Dr Ben Warne
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 16 October 2006 - 10:25 AM

Please look up session ok

Remeber when using session that on all pages you must have

<?php
session_start();?>


I didnt want to do it in a session though, i wanted to use hidden variables

Sorry if i sounded strange, im learning from scratch, and want to cover everything, but am having real trouble with this

#6 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 16 October 2006 - 10:28 AM

you can only hold user information and keep it as the users information if you use cookies or sessions ok.

in your case you want to throw the user from one page to anther so session would work grate ok.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#7 Dr Ben Warne

Dr Ben Warne
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 16 October 2006 - 10:32 AM

you can only hold user information and keep it as the users information if you use cookies or sessions ok.

in your case you want to throw the user from one page to anther so session would work grate ok.


But i dont want to use a session yet, i wanted to use something like

<form name='form1' method='get' onsubmit='forms.form1.userid.value="Abracadabra"'>
<input name='userid' type='hidden'/>

as an example

#8 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 16 October 2006 - 11:40 AM

The code i have provided was a code you wanted and a example of a code that does not use session as you didnt want to.

As you can see from the example i use 2 forms but i do sugest you do look into sessions as the code would of been much easer to write and a lot smaller in size.


The user fill in the form with there name and description.

If the name and description is not filled in the user get's a meesage to fill in all the form.

if all information is filled in then the user gets the information shown to them.

if the user wants to repost the information there is a link to go back to the form to repost the information.

if the information is ok the user use the confirmation button the information posts to a page confirm.php and the relevent information is added to the database with a echoed thank you.


All the best redarrow.


<?php

$name=$_POST['name'];
$description=$_POST['description'];


if(empty($name) || empty($description) ){

echo " sorry please fill in the whole form";

}else{

echo "Your name is:$name <br> you description was: $description";

echo"<form method='POST' action='confirm.php'>";
echo"<input type='hidden' value='$name'>";
echo"<input type='hidden' value='$description'>";
echo"<input type='submit' name='confirm' value='confirm information please'><br><br>
Repost information agin <a href='a.php'>Repost information</a>";
exit;
}
?>

<html>
</head>
<title>test</title>
<body>
<form method="POST" action="<? echo $_SERVER['php_SELF'];?>">
your name please
<br>
<input type="text" name="name">
<br>
Your description please
<br>
<textarea name="description" cols="20" rows="10"> </textarea>
<br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

confirm.php
<?php

$name=trim(addslashes($_POST['name']));
$description=trim(addslashes($_POST['description']));

// database information

if($_POST['confirm']){

$insert="INSERT INTO whatever (name,description) VALUES ('$name','$description')";
mysql_query($insert)or die("insert problams");

echo"Thank you information added to the database";
exit;
}
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#9 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 16 October 2006 - 12:51 PM

Here is a simple in and out example, doing everything on a single page! But I also would add more form validation!

<?

$status = array ( 
		'sr' =>   'Student (Resident)', 
		'snr' =>  'Student (Non-Resident)', 
		'str' =>  'Staff (Resident)', 
		'stnr' => 'Staff (Non-Resident)'
	);

$name     = ( isset ( $_POST['name'] ) && trim ( $_POST['name'] ) != '' ? $_POST['name'] : '' );
$email    = ( isset ( $_POST['email'] ) && trim ( $_POST['email'] ) != '' ? $_POST['email'] : '' );
$address  = ( isset ( $_POST['address'] ) && trim ( $_POST['address'] ) != '' ? $_POST['address'] : '' );
$category = ( isset ( $_POST['category'] ) && isset ( $status[$_POST['category']] ) != '' ? $_POST['category'] : '' );

$error    = '';

if ( isset ( $_POST['confrim'] ) )
{
	if ( ! empty ( $name ) && ! empty ( $email ) && ! empty ( $address ) && ! empty ( $category ) )
	{
		// database insert or other processing here...

		echo "Thanks for your request <strong>" . $name . "</strong>, back to our <a href='/'>home</a> page!";

		exit ();
	}

	$error = 'Data needed to process the form is missing or invald, please check your information!';
}
if ( isset ( $_POST['category'] ) )
{
	if ( ! empty ( $name ) && ! empty ( $email ) && ! empty ( $address ) && ! empty ( $category ) )
	{
		if ( preg_match ( "/^([._a-z0-9-]+[._a-z0-9-]*)\@(([a-z0-9-_]+.)*([a-z0-9-]+)(.[a-z]{2,4}))$/i", $email ) )
		{
?>
<html>
	<head>
		<title>Car Permit Confirmation</title>
	</head>
	<body>
		<h2>Please Confirm Your Information</h2>
		<form action='' method='post'>
			<input type='hidden' name='confrim' value='1' />
			<input type='hidden' name='name' value='<?=htmlspecialchars ( $name, ENT_QUOTES );?>' /><pre>         <strong>Your Name</strong>: <?=$name;?></pre>
			<input type='hidden' name='email' value='<?=htmlspecialchars ( $email, ENT_QUOTES );?>' /><pre><strong>Your Email Address</strong>: <?=$email;?></pre>
			<input type='hidden' name='address' value='<?=htmlspecialchars ( $address, ENT_QUOTES );?>' /><pre><strong>Your House Address</strong>: <?=$address;?></pre>
			<input type='hidden' name='category' value='<?=htmlspecialchars ( $category, ENT_QUOTES );?>' /><pre>     <strong>Category Type</strong>: <?=$status[$category];?></pre>
			<br />
			<br />
			<input type='submit' value='Comfrim Request' /> <input type='button' value='Make Changes' onclick='history.go(-1);' />
		</form>
	</body>
</html>
<?
			exit ();
		}
	}

	$error = 'Data needed to process the form is missing or invald, please check your information!';
}
?>
<html>
	<head>
		<title>Car Permit Application Form</title>
	</head>
	<body>
		<h2>Car permit Application Form</h2>
		<form action='' method='post'>
			<input type='text' name='name' value='<?=htmlspecialchars ( $name, ENT_QUOTES );?>' size=32 />Your name
			<br />
			<input type='text' name='email' value='<?=htmlspecialchars ( $email, ENT_QUOTES );?>' size=32 />Your Email Address
			<br />
			<input type='text' name='address' value='<?=htmlspecialchars ( $address, ENT_QUOTES );?>' size=32 />Your House Address
			<br />
			Which of the following categories do you belong to ?
			<br/>
			<select name='category'>
<?
foreach ( $status AS $k => $v )
{
	echo "				<option value='" . $k . "'" . ( $category == $k ? " selected='selected'" : null ) . ">" . $v . "</option>\r\n";
}
?>
			</select>
			<br/>
			<br />
			<input type='submit' value='Submit Request' />
		</form>
		<br/>
		<?=$error;?>
	</body>
</html>


me!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users