Dr Ben Warne Posted October 16, 2006 Share Posted October 16, 2006 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.htmlAND<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.phpWhat 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 Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 16, 2006 Share Posted October 16, 2006 Just send the user to another page to show there current selected items with a confirm button.Then redirect them to pay. Quote Link to comment Share on other sites More sharing options...
Dr Ben Warne Posted October 16, 2006 Author Share Posted October 16, 2006 [quote author=redarrow link=topic=111629.msg452494#msg452494 date=1160993335]Just send the user to another page to show there current selected items with a confirm button.Then redirect them to pay. [/quote]How do i do that?Also how does it hold the variables for the 3rd page? Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 16, 2006 Share Posted October 16, 2006 Please look up session okRemeber when using session that on all pages you must have [code] <?phpsession_start();?>[/code] Quote Link to comment Share on other sites More sharing options...
Dr Ben Warne Posted October 16, 2006 Author Share Posted October 16, 2006 [quote author=redarrow link=topic=111629.msg452500#msg452500 date=1160994033]Please look up session okRemeber when using session that on all pages you must have [code] <?phpsession_start();?>[/code][/quote]I didnt want to do it in a session though, i wanted to use hidden variablesSorry if i sounded strange, im learning from scratch, and want to cover everything, but am having real trouble with this Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 16, 2006 Share Posted October 16, 2006 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. Quote Link to comment Share on other sites More sharing options...
Dr Ben Warne Posted October 16, 2006 Author Share Posted October 16, 2006 [quote author=redarrow link=topic=111629.msg452504#msg452504 date=1160994517]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.[/quote]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 Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 16, 2006 Share Posted October 16, 2006 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.[code]<?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>[/code]confirm.php[code]<?php$name=trim(addslashes($_POST['name']));$description=trim(addslashes($_POST['description']));// database informationif($_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;}?>[/code] Quote Link to comment Share on other sites More sharing options...
printf Posted October 16, 2006 Share Posted October 16, 2006 Here is a simple in and out example, doing everything on a single page! But I also would add more form validation![code]<?$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>[/code]me! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.