Create multi page forms – Advice needed
-
Hi,
I’m trying to create a multi page form using twentyeleven theme. I’ve created some function codes to test this out and have used $SESSIONS to pass input data from one page to the next. Basically, there are 3 step forms, form1 captures Name & Email, form2 captures Name on card & Credit card number, and form 3 captures Purchase price & Location. Each form will call a corresponding php script to display the next form and so on.
The issue is, form1 displays properly with the page headers and page template, but form2 and 3 just shows a white blank page with the form to capture data. Upon checking with firebug, the <head> section is empty. Did I miss something along the way? I need some advice here.
The codes are as follows:
In functions.php file, the short code was place inside a page to test.function start_compare() { echo '<form method="post" action="https://www.domain.com/wp-content/themes/twentyeleven-child/compare_step2.php">'; echo '<input type="hidden" value="1" name="compare_step">'; echo '<p>Name: <input type="text" name="name"></p>'; echo '<p>Email: <input type="text" name="email_address"></p>'; echo '<input type="submit" value="Next">'; echo '</form>'; } add_shortcode('compare_form', 'start_compare');
In the same folder as functions.php, I created the remaining php script files.
compare_step2.php
<?php session_start(); // Store the collected values in the session variables $_SESSION['name'] = $_POST['name']; $_SESSION['email_address'] = $_POST['email_address']; echo '<form method="post" action="https://www.domain.com/wp-content/themes/twentyeleven-child/compare_step3.php">'; echo '<input type="hidden" value="2" name="compare_step">'; echo '<p>Name on card: <input type="text" name="name_on_card"></p>'; echo '<p>Credit Card No.:<input type="text" name="credit_card_number"></p>'; echo '<input type="submit" value="Back">'; echo '<input type="submit" value="Next">'; echo '</form>'; ?>
compare_step3.php
<?php session_start(); $name = $_SESSION['name']; $email_address = $_SESSION['email_address']; $name_on_card = $_POST['name_on_card']; $credit_card_number = $_POST['credit_card_number']; // Display info collected so far - For debugging echo "<pre>"; print_r($name);echo "</pre>"; echo "<pre>"; print_r($email_address);echo "</pre>"; echo "<pre>"; print_r($name_on_card);echo "</pre>"; echo "<pre>"; print_r($credit_card_number);echo "</pre>"; // Display final form and collect final info here echo '<form method="post" action="https://www.domain.com/wp-content/themes/twentyeleven-child/process_form.php">'; echo '<input type="hidden" value="2" name="compare_step">'; echo '<p>Purchase Price: <input type="text" name="purchase_price"></p>'; echo '<p>Purchase Location:<input type="text" name="purchase_location"></p>'; echo '<input type="submit" value="Back">'; echo '<input type="submit" value="Submit">'; echo '</form>'; ?>
process_form.php
<?php // Write collected info details to database here // Not coded yet // Finally, destroy session session_destroy(); ?>
- The topic ‘Create multi page forms – Advice needed’ is closed to new replies.