Opening a URL with PHP (solved)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Opening a URL with PHP (solved)

Post by Bigun »

I'd like to open a URL with PHP.

I've made a form to ask for information. and after the HTML form is filled out, it calls a PHP file I made that checks over the input from the HTML to be sure that it's all filled out. If it is not, I'd like for the PHP to display what wasn't filled out, then redisplay the HTML form page.

I've gotten the PHP code to display the errors, but how to I reopen the HTML form below the errors?

http://www.cybergrunge.com/test/newuser.html
Last edited by Bigun on Tue Jun 13, 2006 1:08 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Store the HTML in the script and have it submit to itself.
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Post by Bigun »

So, there is no way to re-display the page along with the errors?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Sure, there is, but depending on how you want them integrated, it'd have to be a script anyways.
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Post by Bigun »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


You can easily see the source for http://www.cybergrunge.com/test/newuser.html.

Here's http://www.cybergrunge.com/test/newuser.php

Code: Select all

<?php

if ($username == "") {
        echo "<font color=red><b>Please fill in a username</b></font><br>";
        $failed = yes;
}

if ($fname == "") {
        echo "<font color=red><b>Please fill in your first name</b></font><br>";
        $failed = yes;
}

if ($lname == "") {
        echo "<font color=red><b>Please fill in your last name</b></font><br>";
        $failed = yes;
}

if ($email == "") {
        echo "<font color=red><b>Please fill in an e-mail address</b></font><br>";
        $failed = yes;
}

if ($password == "") {
        echo "<font color=red><b>Please type in a password</b></font><br>";
        $failed = yes;
}

if ($vpassword == "") {
        echo "<font color=red><b>Please re-type your password</b></font><br>";
        $failed = yes;
}

if ($legalagree == "") {
        echo "<font color=red><b>Please read over the legal requirements and check the box below them</b></font><br><br>";
        $failed = yes;
}

if ($password != $vpassword) {
        echo "<font color=red><b>Your passwords do not match, please retype them</b></font><br>";
        $failed = yes;
}

include "audit.php";
if (audit()) {

} else {
        echo "<font color=red><b>Please type in the correct text from the picture into the box below</b></font><br>";
        $failed = yes;
}

if ($failed == "yes") {
        $url = fopen("http://www.cybergrunge.com/test/newuser.html", "r");
        echo $url;
} else {

}

php?>
That last bit of code is me trying to reopen the newuser.html page.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Post by Bigun »

Wait, it took a second for all that to sink in...

The form would need to be PHP then re-display/display the HTML via echo commands?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I personally always have the form submit to itself, and do the validation at that point.. a very simple example would be

Code: Select all

<?php 
 
   //default error to false
   $errors = false;  

   if ($_SERVER['REQUEST_METHOD'] == 'POST')
   {
      //lets check for errors here

      if ($error == true) 
      { 
         echo $error_message;
      }
      else
      {
          //we did not detect any errors, so lets move him to the next page
          header('Location: nextpage.php');
      }     
   }


   //display the form here

?>

   <form>
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Post by Bigun »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Got it:

http://www.cybergrunge.com/test/newuser.php:

Code: Select all

<?php

if ($username != "" || $fname != "" || $lname != "" || $email != "" || $password != "" || $vpassword != "" || $legaleagree != "") {
        
        $failed = "no";

        if ($username == "") {
                echo "<center><font color=red><b>Please fill in a username</b></font><br></center>";
                $failed = "yes";
        }

        if ($fname == "") {
                echo "<center><font color=red><b>Please fill in your first name</b></font><br></center>";
                $failed = "yes";
        }

        if ($lname == "") {
                echo "<center><font color=red><b>Please fill in your last name</b></font><br></center>";
                $failed = "yes";
        }

        if ($email == "") {
                echo "<center><font color=red><b>Please fill in an e-mail address</b></font><br></center>";
                $failed = "yes";
        }

        if ($password == "") {
                echo "<center><font color=red><b>Please type in a password</b></font><br></center>";
                $failed = "yes";
        }

        if ($vpassword == "") {
                echo "<center><font color=red><b>Please re-type your password</b></font><br></center>";
                $failed = "yes";
        }

        if ($legalagree == "") {
                echo "<center><font color=red><b>Please read over the legal requirements and check the box below them</b></font></center><br><br>";
                $failed = "yes";
        }

        if ($password != $vpassword && $password != "" && $vpassword != "") {
                echo "<center><font color=red><b>Your passwords do not match, please retype them</b></font></center><br>";
                $failed = "yes";
        }
        include "audit.php";
        if (audit()) {
      
        } else {
                echo "<center><font color=red><b>Please type in the correct text from the picture into the box below</b></font></center><br>";
                $failed = "yes";
        }
}

if ($failed == "no") {
        //Insert insertion code and successful add message here
        break;
}

echo "<html>";
echo "<title>NewUser Form - CyberGrunge.com</title>";
echo "<body background=\"http://www.cybergrunge.com/images/bg3.jpg\">";

echo "<style type=\"text/css\">";
echo "<!--";
echo "em";
echo "   {";
echo "   color:grey;";
echo "   font-style:normal;";
echo "   }";

echo "h1";
echo "   {";
echo "   color:black;";
echo "   font-style:normal;";
echo "   font-size:20;";
echo "   }";
echo "-->";
echo "</style>";

echo "<form action=\"newuser.php\" method=\"post\">";
echo "  <br>";
echo "  <center>";
echo "  <font size=5 color=red>**Notes**</font><br>";
echo "  <table width=300 border=6 bordercolor=red bgcolor=black>";

echo "  <tr>";
echo "          <td>";
echo "                  <center><em><sup>*</sup> = Denotes a Required Field</center>";
echo "                  <br>";
echo "                  The First and Last Name of the account is considered the owner of the account.  Any issues, decisions, changes, or implications of the account are handled by said person.</em><br>";
echo "          </td>";
echo "  </tr>";

echo "  </table>";
echo "  <br>";
echo "  <br>";
echo "  <center>";
echo "  <h1>Account Info</h1>";
echo "  </center>";
echo "  <table border=3 bordercolor=black bgcolor=black>";
echo "  <tr>";
echo "          <td align=right><em>Desired UserName:<br>Alphanumeric characters<br>and underscores only</em></td>";
echo "          <td align=left><sup><em>*</em></sup><input tupe=\"text\" name=\"username\"></td>";
echo "  </tr>";
echo "  <tr>";
echo "          <td align=right><em>Your First Name:</em></td>";
echo "          <td align=left><sup><em>*</em></sup><input type=\"text\" name=\"fname\"></td>";
echo "  </tr>";
echo "  <tr>";
echo "          <td align=right><em>Your Last Name:</em></td>";
echo "          <td align=left><sup><em>*</em></sup><input type=\"text\" name=\"lname\"></td>";
echo "  </tr>";
echo "  <tr>";
echo "          <td align=right><em>E-mail:</em></td>";
echo "          <td align=left><sup><em>*</em></sup><input type=\"text\" name =\"email\"></td>";
echo "  </tr>";
echo "  <tr>";
echo "          <td align=right><em>Password:</em></td>";
echo "          <td align=left><sup><em>*</em></sup><input type=\"password\" name=\"password\"></td>";
echo "  </tr>";
echo "  <tr>";
echo "          <td align=right><em>Retype Password:</em></td>";
echo "          <td align=left><sup><em>*</em></sup><input type=\"password\" name=\"vpassword\"></td>";
echo "  </tr>";
echo "  </table>";
echo "  <br>";
echo "  <br>";
echo "  Legal Jargon - blah blah blah<br>";
echo "  <br>";
echo "  <input type=\"checkbox\" name=\"legalagree\">: I agree to the legal terms and conditions listed above<br>";
echo "  <br>";
echo "  <img width=120 height=30 src=\"button.php\" border=\"1\"><br>";
echo "  <br>";
echo "  --Input the text above into the box below--<br>";
echo "  --This is to be sure that you are not a bot--<br>";
echo "  <br>";
echo "  <input maxlength=5 size=5 name=\"userdigit\" type=\"text\" value=\"\"><br>";
echo "  <br>";
echo "  <input type=\"submit\" value=\"Submit\">";
echo "  </center>";
echo "</form>";

echo "</body>";
echo "</html>";


php?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply