sayedsohail Posted August 24, 2007 Share Posted August 24, 2007 I got a index.php file with two fields and would like to verify this fields using iframe behind the scenes, than wish to display results of iframe in the index.php file below the name and email fields. When i open the index.php file it just display the form and errors, i wish to execute it when i press the submit button and reset the form. Here is the code: index.php <?php session_start(); echo "<form name='f2' action='verifyframe' method='post' target='verifyframe'>"; echo "Name<INPUT type='text' value='' id='name'>" echo "email<INPUT type='email' value='' id='email'>" echo "<INPUT type='submit' value='submit' id='submit'></FORM>" ?> <iframe id="verifyframe" name="verifyframe" style="width:480px; height:300px; border:1px; visibility:hidden;" src="verify.php"></iframe> verify.php <?php $errors=array(); if (!$_POST['name']) // if not, add that error to our array $errors[] = "Name is required"; if (!$_POST['email']) // if not, add that error to our array $errors[] = "email is required"; if (count($errors)>0){ echo "<strong>ERROR:<br>\n"; foreach($errors as $err) echo "$err<br>\n"; } else { //rest of the functions. } Quote Link to comment https://forums.phpfreaks.com/topic/66546-solved-form-and-iframe-not-working/ Share on other sites More sharing options...
lemmin Posted August 24, 2007 Share Posted August 24, 2007 You should post what the errors are. You do need to change this, though: echo "<form name='f2' action='verifyframe' method='post'>"; needs to be: echo "<form name='f2' action='verify.php' target='verifyframe' method='post'>"; Quote Link to comment https://forums.phpfreaks.com/topic/66546-solved-form-and-iframe-not-working/#findComment-333283 Share on other sites More sharing options...
sayedsohail Posted August 24, 2007 Author Share Posted August 24, 2007 now there are no errors, i wish to show the validation results from verify.php in the parent document, still keeping the iframe hidden. but this is not happening. i don't know how to achieve this? Quote Link to comment https://forums.phpfreaks.com/topic/66546-solved-form-and-iframe-not-working/#findComment-333290 Share on other sites More sharing options...
lemmin Posted August 24, 2007 Share Posted August 24, 2007 PHP doesn't have events, therefore, you can't really do much with it dynamically. Using your method, the only way you can do what you want is to make the iframe just big enough to display the red text and have it positioned where you want that text to be. It would just be a blank iframe the same color as the background until it gets executed, then, if there is an error you can print out the red. There isn't any other way to do this without refreshing the page. Quote Link to comment https://forums.phpfreaks.com/topic/66546-solved-form-and-iframe-not-working/#findComment-333296 Share on other sites More sharing options...
sayedsohail Posted August 24, 2007 Author Share Posted August 24, 2007 This is what i tried/change inside the verify.php file but no success. i f (count($errors)>0){ echo "<iframe id='errors' style='visibility:visible;'><strong>ERROR:</strong><br>\n"; foreach($errors as $err) echo "$err<br>\n"; } echo "</iframe>"; else { Echo " No errors found"; //rest of the functions. } Quote Link to comment https://forums.phpfreaks.com/topic/66546-solved-form-and-iframe-not-working/#findComment-333303 Share on other sites More sharing options...
lemmin Posted August 24, 2007 Share Posted August 24, 2007 Everything works accept the error is shown in the iframe, right? When you get an error it shows up underneath the form? That is the only way you can do it, so that is fine. You can keep all your php the same, just embed the iframe in the exact spot you want the error to show up. Also, change the background of the iframe to the same color as your main page (if it isn't already.) The idea is that, the main page stays static, but the iframe changes from a blank page to a page with error messages. Quote Link to comment https://forums.phpfreaks.com/topic/66546-solved-form-and-iframe-not-working/#findComment-333313 Share on other sites More sharing options...
sayedsohail Posted August 24, 2007 Author Share Posted August 24, 2007 yes this is exactly i wanted to do, where do i apply the changes in my script. Quote Link to comment https://forums.phpfreaks.com/topic/66546-solved-form-and-iframe-not-working/#findComment-333317 Share on other sites More sharing options...
lemmin Posted August 24, 2007 Share Posted August 24, 2007 Unless your output isn't what I think it is, all you have to do is move the <iframe> object around. For example, if you put that block above your <?php?> block, it will display the error above the form. You can mess around will all the html positioning and sizes until you get it in the spot you want. Quote Link to comment https://forums.phpfreaks.com/topic/66546-solved-form-and-iframe-not-working/#findComment-333321 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.