Jump to content

Recommended Posts

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.
}

Link to comment
https://forums.phpfreaks.com/topic/66546-solved-form-and-iframe-not-working/
Share on other sites

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.

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.
}

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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