Jump to content

Storing form data as a PHP session


adambedford

Recommended Posts

I'm creating a web application that needs visitors to be able to pay with paypal. I want customers to fill in the form that will store their information in a database and then be transferred to paypal to complete the transaction.

 

I don't want the record in the database to be created until the payment has been authorised (so maybe it could be done when the confirmation page loads when the visitor is returned to my site from paypal?)

 

My queestion is this: How do I store the data they entered in the form temporarily while they complete payment and then write it permanently once confirmation is received?

 

I'm thinking that I could store the data as a session  and then write this to the table on the confirmation page. Would that work? If so, how would I go about it? (I'm relatively new to PHP).

 

PS. If anyone knows anything about the PayPal API and payment authentication as well that would be brilliant!

Link to comment
https://forums.phpfreaks.com/topic/191143-storing-form-data-as-a-php-session/
Share on other sites

So how would I go about storing the data entered in this form as session variables?

 

<form id="form" name="form" method="post" action="">
<div id="websitewrapper">
  <label for="Website_name" class="label_left">Website Name</label>
  <input type="text" name="Website_name" id="Website_name" />
</div>
<div id="URLwrapper">
  <label for="URL2" class="label_left">URL (Web Address)</label>
  <input type="text" name="URL" id="URL2" />
</div>
<div id="descriptionwrapper">
  <label for="Description2" class="label_left">Description</label>
  <textarea name="Description" cols="35" rows="4" id="Description2"></textarea>
</div>
<div id="categorywrapper">
  <label for="Category_ID2" class="label_left">Category</label>
  <select name="Category_ID" size="1" id="Category_ID2">
  </select>
</div>
<div id="highlightwrapper">
  <label for="Highlighted2" class="label_left">Highlighted</label>
  <input type="checkbox" name="Highlighted" value="Highlighted" id="Highlighted" />
</div>
<div id="featuredwrapper">
  <label for="Featured2" class="label_left">Featured</label>
  <input type="checkbox" name="Featured" value="Featured" id="Featured" />
</div>
<div id="homepagewrapper">
  <label for="Homepage2" class="label_left">Homepage Featured</label>
  <input type="checkbox" name="Homepage" value="Homepage" id="Homepage" />
</div>
</form>

I'm not 100% sure how the values work with checkboxes, but you would do something like this:

// $_POST data validation code can go here to make sure data is ok for use.
session_start();   // start session
foreach($_POST as $keyName => $value)   // loop through $_POST array values
{
   $_SESSION[$keyName] = $value;   // assign each value of $_POST to a session variable of the same name
}

 

Try doing print_r($_POST); and print_r($_SESSION); to look at the data inside the $_POST and $_SESSION arrays to debug and ensure your data is travelling around and being stored correctly.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.