wiggst3r Posted October 2, 2008 Share Posted October 2, 2008 Hi I have a form, that has a hidden field. The hidden field is an email address called, original_email, which is the email address from the referer The form, has fields such as name, email etc. All the details are passed into a database, with 2 tables: added_friends (id, name, email, entry_id, original_email) - is the table where, a second form details go (this is where fred@fredt.com can submit friends email addresses, such as fred@fredddd.com) entries (id name, post_code, email, date_of_birth, last_visit, referer_id) - is the table where the form details are posted What I'm looking to do, is: 1) The forms URL has the following passed: http://www.domain.com/index.php?name=craig&email=fred@fredt.com 2) Therefore the hidden field has a value of fred@fredt.com 3) User then changes his/her email address in the form to something else (i.e. fred@freddddd.com) 4) When user submits the form, his details are passed into the database. 5) fred@fredt.com has an id (e.g 25) 6) fred@freddddd.com has a refer_id column, which must be updated to include the id of fred@fredt.com (since he has refered him, so his refer_id will be 25) 7) fred@freddddd.com submits his details, his details are inserted into the db, check the added_friends table, get fred@fredt.com's id, insert this id into the entries table for fred@freddddd.com as the refer_id My code is as follows: <?php require(dirname(__FILE__) . "/shared.php"); class IndexView extends Shared { function display_form($error_messages = array()) { $this->html_top(); $this->_form($error_messages); $this->html_bottom(); } function _form($error_messages = array(), $unique_code = false) { ?> <?php if(count($error_messages)) { ?><ul id="errors"><?php foreach($error_messages as $error) { ?> <li><?=$error?></li> <?php } ?></ul><?php } ?> <table id="formReg"> <form id="pizza_form" name="pizza_form" action="index.php" method="post"> <tr> <td><input type="hidden" name="state" value="validate_submission"/></td> </tr> <tr> <td class="formLabel">Full name*</td> <td><?= create_input_field('', 'name', isset($_GET['name'])?$_GET['name']:'') ?></td> </tr> <tr> <td class="formLabel">Email*</td> <td><?= create_input_field('', 'email', isset($_GET['email'])?$_GET['email']:'') ?></td> </tr> <tr> <td></td> <td><a href="#" onclick="clear_out_name_and_email();">Not your details?</a></td> <tr> <td class="formLabel">Post Code*</td> <td><?= create_input_field('', 'post_code') ?></td> </tr> <tr> <td class="formLabel">Date Of Birth</td> <td><?= create_select_list('', 'dob_day', $options = $this->days_of_month_array() )?> <?= create_select_list('', 'dob_month', $options = $this->months_array() )?> <?= create_select_list('', 'dob_year', $options = $this->years_array() )?></td> </tr> <tr> <td></td> <td>We all like to celebrate birthdays...</td> </tr> <tr> <td class="formLabel">Last Pizza express visit</td> <td><?= create_select_list('', 'last_visit', $options = $this->visits_array() )?></td> </tr> <tr> <td><input type="hidden" name="unique_code" id="unique_code" value="<?=$unique_code?>"/></td> </tr> <tr> <td class="formLabel"><?= create_check_box('agree_terms', '', $checked=0, '') ?></td> <td>I have read and agree to the voucher <a href="#" title="terms and conditions" onclick="popTerms();">terms and conditions</a></td> </tr> <?php if(isset($_GET['email'])) { $orig_email = $_GET['email']; } elseif(isset($_POST['original_email'])) { $orig_email = $_POST['original_email']; } else { $orig_email = ''; } ?> <tr> <td><input type="hidden" name="original_email" id="original_email" value="<?=$orig_email?>"/></td> <td><input type="image" src="../images/btn-submit.gif" alt="Click here to print your voucher" onclick="onsubmit(); return false;" /></td> </tr> <?php } function display_voucher($row) { $this->html_top(); $row['id'] = 'AB140-2008-' . $row['id']; ?> <h1>Voucher for <?=$row['name']?></h1> <img src="barcode/wrapper.php?p_bcType=1&p_text=<?=$row['id']?>&p_xDim=2&p_w2n=3&p_charGap=2&p_invert=N&p_charHeight=60&p_type=1&p_label=Y&p_rotAngle=0&p_checkDigit=N" ALT="<?=$row['id']?>"> <br/> Email: <?=$row['email']?> <br/> Dob: <?=make_db_date_into_english_date($row['date_of_birth'])?> <br/> <?php $visit_array = $this->visits_array(); ?> Last Visited: <?=$visit_array[$row['last_visit']]?> <br/><br/> <?php echo create_link($params = array('state' => 'clear_session'), $file_name = 'index.php', $text = 'New Voucher'); ?> <br/> <a href="JavaScript:window.print();">Print this page</a> <h2>Forward this offer to up to 5 friends</h2> <?php if(isset($_GET['message']) && $_GET['message'] == 'friends_were_added') { ?><p>Thanks, we have emailed your friends</p><?php } else { ?> <form name="friend_form" method="post" action="index.php"> <input type="hidden" name="state" value="tell_friends"/> <input type="hidden" name="entry_id" value="<?=$row['id']?>"/> <?php for($i=1;$i<=5;$i++) { ?> <label for="friend_name_<?=$i?>">Friend <?=$i?> Name</label> <?= create_input_field('', "friend_name_$i") ?> <label for="friend_email_<?=$i?>">Friend <?=$i?> Email</label> <?= create_input_field('', "friend_email_$i") ?> <br/> <?php } ?> <input type="submit" value="submit"/> </form> <?php } $this->html_bottom(); } function days_of_month_array() { $r = array('' => ''); for($i=1;$i<=31;$i++) { $r[$i] = $i; } return $r; } function months_array() { $r = array('' => '', '1' => 'Jan', '2' => 'Feb', '3' => 'Mar', '4' => 'Apr', '5' => "May", '6' => 'Jun', '7' => 'Jul', '8' => 'Aug', '9' => 'Sep', '10' => 'Oct', '11' => 'Nov', '12' => 'Dec'); return $r; } function years_array() { $r = array('' => ''); for($i=1992;$i>1910;$i--) { $r[$i] = $i; } return $r; } function visits_array() { return array('' => '', 'last_fornight' => 'Within the last fortnight', 'last_month' => 'Within the last month', '6_months' => 'Within the last 6 months', 'over_1_year' => 'More that a year ago', 'first_time' => 'This is my first time'); } } ?> Any ideas? Thanks 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.