Jump to content

Recommended Posts

Ok I have an account creation system that consists of 3 forms. I have done alot of reading on sessions, and as I understand what they do and how they work, I dont understand how to actually implement it into my forms. Now form1.php is all input boxes as is form3.php but form2.php has one section of check boxes. Then I have form4.php which is where all the input that was put into the other forms will be "echoed" for the person to verify all the information. With all that said I guess here is a simple way to ask the question and perhaps get an answer that will help me with all of this. Since there is so much code on the forms thats why I havent posted them.

Ok so can anyone give me an example that would work for what I am looking to do?

 

Thanks alot for the help

Link to comment
https://forums.phpfreaks.com/topic/101721-session-gloomies/
Share on other sites

I was hoping I could just edit the last post. Anyway I should mention I do have form3.php working using...

<?php
session_start();
//below is the session code for step3.php
foreach( $_POST as $key => $val )
{
    $_SESSION['form3'][$key] = $val;
}
?>

I have this posted on from4.php and this works, so is there a way I could use something like this but for all 3 forms, without any issues?

Link to comment
https://forums.phpfreaks.com/topic/101721-session-gloomies/#findComment-520455
Share on other sites

It would help to have a little bit more information on the problem.  You seem to have an understanding of sessions, because you implemented them just fine in the example you gave.

 

For each page, you just create a session variable for every single value.  You can just set a session variable equal to a post variable.

 

<?php
\\ Example

$_SESSION['varname'] = $_POST['formname']

?>

Link to comment
https://forums.phpfreaks.com/topic/101721-session-gloomies/#findComment-520827
Share on other sites

Eh, just give each element a different name across all 3 pages and include this at the top of page 2, 3 and 4

 

<?php

$_SESSION['form_vars'] = $_POST;

?>

 

Then on page4.php

 

<?php

function echoFormVar($varname) {
    if ( isset($_SESSION['form_vars'][$varname]) )
        // Prevent XSS injection
        echo htmlentities($_SESSION['form_vars'][$varname]);
}


echoFormVar('textbox1');
echo '<br>';
echoFormVar('textbox2');

// ect..

?>

Link to comment
https://forums.phpfreaks.com/topic/101721-session-gloomies/#findComment-520839
Share on other sites

Well here is form1.php (actually called step1.php) so here is the code for it, perhaps this will help and thank you both.

 

<?php session_start(); ?>
<?php include ('header.inc.php'); ?>
<div class = "nround">
<div class = "ntop"><h2>Become a hotspot</h2></div>
<div class = "nmiddle" align="left">

<form name="step1" method="post" action="step2.php">
<table border="0" cellpadding="2" cellspacing="0" width="100%">
<tbody>
<tr>
<td colspan="2"><b>Please enter a username and password that you will use to access your account.</b>
</td>
</tr>
<tr>
<td class="required">Username</td>
<td class="required"><input type="text" name="username" size="20" maxlength="15" 
value="<?php if( isset($_SESSION['form1']['username']) ) echo $_SESSION['form1']['username']; ?>" /></td>
</tr>
<tr>
<td class="required">Password</td>
<td class="required"><input type="password" name="password" size="20" maxlength="15" 
value="<?php if( isset($_SESSION['form1']['password']) ) echo $_SESSION['form1']['password']; ?>" /></td>
</tr>
<tr>
<td colspan="2"><b>Please enter a valid e-mail address to use in order to activate your account.</b>
</td>
</tr>
<tr>
<td class="required">Company Name</td>
<td class="required"><input type="text" name="comp_name" size="20" maxlength="15" 
value="<?php if( isset($_SESSION['form1']['comp_name']) ) echo $_SESSION['form1']['comp_name']; ?>" /></td>
</tr>
<tr>
<td class="required">Establishment Type</td>
<td class="required">
<select name="comp_type" 
value="<?php if( isset($_SESSION['form1']['comp_type']) ) echo $_SESSION['form1']['comp_type']; ?>" />
<option selected>- Select One -</option>
<option id="bars" value="Bar">Bar</option>
<option id="clubs" value="Club">Club</option>
<option id="coffee_shops" value="Coffee Shop">Coffee Shop</option>
<option id="resturants" value="Resturant">Resturant</option>
</select>
</td>
</tr>
<tr>
<td class="required">Address</td>
<td class="required"><input type="text" name="comp_address" size="30" maxlength="30" 
value="<?php if( isset($_SESSION['form1']['comp_address']) ) echo $_SESSION['form1']['comp_address']; ?>" /></td>
</tr>
<tr>
<td class="required">City/Zip</td>
<td class="required"><input type="text" name="comp_city" size="10" maxlength="30" 
value="<?php if( isset($_SESSION['form1']['comp_city']) ) echo $_SESSION['form1']['comp_city']; ?>" />
<input type="text" name="comp_zip" size="5" maxlength="5" 
value="<?php if( isset($_SESSION['form1']['comp_zip']) ) echo $_SESSION['form1']['comp_zip']; ?>" /></td>
</tr>
<tr>
<td class="required">Phone Number</td>
<td>(<input type="text" name="comp_area" size="1" maxlength="3" 
value="<?php if( isset($_SESSION['form1']['comp_area']) ) echo $_SESSION['form1']['comp_area']; ?>" />) -
<input type="text" name="comp_phone" size="8" maxlength="8" 
value="<?php if( isset($_SESSION['form1']['comp_phone']) ) echo $_SESSION['form1']['comp_phone']; ?>" /></td>
</tr>
<tr>
<td class="required">Email Address</td>
<td><input type="text" name="comp_email" size="30" maxlength="20" 
value="<?php if( isset($_SESSION['form1']['comp_email']) ) echo $_SESSION['form1']['comp_email']; ?>" /></td>
</tr>
<tr>
<td class="required">Website Address</td>
<td><input type="text" name="comp_web" size="30" maxlength="20" 
value="<?php if( isset($_SESSION['form1']['comp_web']) ) echo $_SESSION['form1']['comp_web']; ?>" /></td>
</tr>
<tr>
<td class="required" valign="top">Description</td>
<td><textarea name="comp_desc" cols="50" rows="12">
<?php if( isset($_SESSION['form1']['comp_desc']) ) echo $_SESSION['form1']['comp_desc']; ?></textarea></td>
</tr>																																																															
<tr>
<td class="verdana11" align="right" width="125"><p></td>
<td><a href="step2.php"><img src="img/step2.gif" alt="" border="0"></a></td>
</tr>
</tbody>
</table>
</form>
</div>
<div class = "nbottom"></div>
</div>
<?php include ('footer.inc.php'); ?>

 

I havent touched this project for sometime so its a little rough and I may change up quite a few things.

Link to comment
https://forums.phpfreaks.com/topic/101721-session-gloomies/#findComment-520895
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.