silentbravo Posted December 15, 2008 Share Posted December 15, 2008 When I submit a validated page through this form http://glenwoodpharmacy.com/bim.php, It redirects to a blank page(itself) and then it goes to the page that would send the email. When it posts to itself, the form is cleared and probably all the variables with it, and then the Captcha, which relies on sessions fails to validate... Also If you know of a better way to do it / tutorial, point me in the direction, this is kind of a mash up of various sources/methods. code below: <?php //print a text box function input_text($element_name, $values, $size) { print '<input type="text" name="' . $element_name .'" value="'; print htmlentities($values[$element_name]) . '"'; print ' style="width: ' . $size . '">'; } //print a text area function input_textarea($element_name, $values) { print '<textarea name="' . $element_name .'"'; print ' style="width: 248px; height: 90px;">'; print htmlentities($values[$element_name]) . '</textarea>'; } // The main page logic: // - If the form is submitted, validate and then process or redisplay // - If it's not submitted, display if ($_POST['_submit_check']) { // If validate_form() returns errors, pass them to show_form() if ($form_errors = validate_form()) { show_form($form_errors); } else { // The submitted data is valid, so process it process_form(); } } else { // The form wasn't submitted, so display show_form(); } function show_form($errors = '') { // IF statement below this isnt used for anything, part of the original code, doesnt do anything if ($_POST['_submit_check']) { $defaults = $_POST; } else { $defaults = array('delivery' => 'yes', 'size' => 'medium'); } //this is used for validation if ($errors) { $error_text = '<p>You need to correct the following errors:'; $error_text .= '<ul><li>'; $error_text .= implode('</li><li>',$errors); $error_text .= '</li></ul></p>'; } else { $errors = ''; } ?> <h1>Prescription Refill Page</h1> <form method="POST" action="<?php print $_SERVER['PHP_SELF']; ?>"> <table style="width: 60%; margin-left: 2em;"> <tr> <td>Name</td><td style="width: 80%;"><?php input_text('name', $defaults, '187px') ?> </td> </tr> <tr> <td>Email</td><td><?php input_text('email', $defaults, '187px') ?> </td> </tr> <tr> <td>Phone</td><td><?php input_text('phone', $defaults, '80px') ?></td> </tr> <tr> <td>RX</td><td><?php input_text('rx', $defaults, '139px') ?></td> </tr> <tr> <td colspan="2" style="text-align: center;"><br /></td> </tr> <tr> <td colspan="2" style="text-align:center;"><?php input_textarea('comments', $defaults); ?> </td> </tr> <tr> <td colspan="2" style="text-align: center;"> <p style="text-align: center;" align="center"> <img id="captcha" src="/securimage/securimage_show.php" alt="CAPTCHA Image" /><br /> <br /> <input type="text" name="captcha_code" size="10" maxlength="6" /> <a href="" onclick="document.getElementById('captcha').src = '/securimage/securimage_show.php?' + Math.random(); return false">Reload Image</a></p> <input name="send" type="submit" id="send" value="Submit"><br /> <div align="center" class="errmsg"><br /><?php print $error_text;?></div> </td> </tr> </table> <input type="hidden" name="_submit_check" value="1"/> </form> <?php } function validate_form() { $errors = array(); function isEmail($email) { return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email)); } if (! strlen(trim($_POST['name']))) { $errors[] = 'Please enter your name.'; } if (! strlen(trim($_POST['email']))) { $errors[] = 'Please enter your Email address'; } if(!isEmail(trim($_POST['email']))) { $errors[] = 'Your Email address is not valid'; } if (! strlen(trim($_POST['phone']))) { $errors[] = 'Please enter Phone number'; } if (! strlen(trim($_POST['rx']))) { $errors[] = 'Please enter your RX Number'; } if (! strlen(trim($_POST['comments']))) { $errors[] = 'Please enter your Comments'; } return $errors; } function process_form() { print "<meta http-equiv=\"refresh\" content=\"0;URL=refill.php\">"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/137122-page-redirect-and-form-post-issue/ Share on other sites More sharing options...
silentbravo Posted December 17, 2008 Author Share Posted December 17, 2008 Anyone? I need this page to redirect to another page, that sends it via email / validates the captcha, right now it sends to itself after clicking submit, and then it redirects which breaks the session for the captcha (at least I think that's what's happening) Quote Link to comment https://forums.phpfreaks.com/topic/137122-page-redirect-and-form-post-issue/#findComment-718024 Share on other sites More sharing options...
premiso Posted December 17, 2008 Share Posted December 17, 2008 You need to add session_start to the top of each page that uses session (before any output) for sessions to work. Quote Link to comment https://forums.phpfreaks.com/topic/137122-page-redirect-and-form-post-issue/#findComment-718030 Share on other sites More sharing options...
silentbravo Posted December 17, 2008 Author Share Posted December 17, 2008 It doesn't use the session on the form page, It calls the session on the page that sends the email, I think it's an error in the logic, the page submits, then redisplays itself but with no form, and then redirects, it needs to just submit and redirect, Not lose the data after submitted/validated Quote Link to comment https://forums.phpfreaks.com/topic/137122-page-redirect-and-form-post-issue/#findComment-718046 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.