Jump to content

tefuzz

Members
  • Posts

    70
  • Joined

  • Last visited

    Never

Everything posted by tefuzz

  1. still new to PHP...i searched but i couldn't find exactly what i was hoping for. I have a simple contact form . it has 3 text inputs and 1 text area. All I am having it do is a simply email the results to someone. I want to validate the fields using php and then output any errors to the correct spot on the form...What I am having trouble deciding is when to do the error checking...I am running the site completely off my index.php (using page values like index.php?p=contact) I want to check all the fields for errors, and make the user aware of all the errors at once. I have seen examples of error checking functions and validation but I cant seem to figure out how to make them work the way I want... <?php if (!isset($_POST['sub'])) { // if the user hasn't submitted the form, display the page normally echo <<<_HTML <div id="contactUs"> <!-- beginning of the contact us page code --> <div class="Row"><!-- top row--> </div><!--top row--> <div id="leftCol"><!-- left column--> <div id="contactForm"> <!-- contact form --> <table width="400" border="0" cellpadding="0" cellspacing="0"> <form name="contact" class="myform" method="post" action="index.php?p=contact&a=submit"> <input type="hidden" name="sub" /> <!-- make sure form is posted --> <tr> <td width="150"> <label>Full Name <span class="small">first & last</span></label></td> <td width="250"><input name="name" type="text" id="name" tabindex="1" dir="ltr" lang="en" maxlength="65" /></td> </tr> <tr> <td><label>Email Address <span class="small">your@email.com</span></label></td> <td><input name="email" type="text" id="email" tabindex="2" dir="ltr" lang="en" maxlength="65" /></td> </tr> <tr> <td><label>Telephone <span class="small">xxx-xxx-xxxx</span></label></td> <td><input name="phone" type="text" id="phone" dir="ltr" lang="en" maxlength="12" /></td> </tr> <tr> <td valign="top"><label>Comments<span class="small">or questions?</span></label></td> <td><textarea name="comments" cols="30" rows="7" tabindex="4"></textarea></td> </tr> <tr><td> </td><td><button type="reset">Clear</button> <button type="submit">Submit</button></td> </tr> </form> </table> </div> <!--contact form --> </div><!-- left column --> <div id="rightCol"><!-- right column --> </div> <!-- right column --> <div class="Row"><!-- bottom row--> </div> <!--bottom row --> </div> <!--contact us page --> _HTML; } elseif (isset($post['sub'])) { $fname = $_POST['name']; $ftel = $_POST['phone']; /* set new variables with the information from the form */ $femail = $_POST['email']; /* in case one is invalid, all the good fields will be entered*/ $fcomment = $_POST['comments']; /* on the form so user doesn't have to retype them all */ /* THIS IS WHERE I WOULD VALIDATE AND OUTPUT */ thats as far as I got with the code...the top half is where I am checking to see if "sub" is set, which if it is not i want the form to display normally. Then under that, I am checking in case it is I set variables for my form fields so I can validate them. Now, how do I validate them and output individual errors for the fields which are incorrect? I have a form inside a table which is positioned by CSS on my page. So for example, if there was an error in the "Name" text field (validating using $fname), i would want it to output something like this in the area of the HTML where the name input is. <td width="150"> <label>Full Name <span class="small">first & last</span></label></td> <td width="250"><input name="name" type="text" id="name" tabindex="1" dir="ltr" lang="en" maxlength="65" /> <span class="smallError">* required</span></td> Am I explaining this right? I can see how i want it to go in my head, i just dont know if I am explaining it right...
  2. I added everything to a table, now it all lines up properly but i am having a problem getting the label font size to appear properly...i have both forms on the same page, one inside a table and one outside (for testing purposes) now the form inside the table is displaying the label font size as about 14, where it is clearly set to 12 within the CSS. the form outside the tables is displaying fine...any ideas?
  3. i have a form...i have it styled using css, however my buttons always line up on the far right no matter what i change...as well, i have a label that is right up against a textarea, but the other labels are spaced fine...can somebody take a look, i think i just need a second set of eyes now. only the relevant code is shown here... <style> #contactUs { margin: 0 auto 30px; padding: 0px; height: auto; width: 845px; text-align: left; } #contactUs #leftCol { height: auto; width: 425px; text-align:left; float: left; background-color: #F0E8CE; margin: 0 auto 30px; } #contactUs #rightCol { float: right; width: 420px; text-align: left; right: 0px; background-color: #F0E8CE; margin: 0 auto 30px; } #contactUs .Row { clear: both; width: 845px; height:auto; background-color: #F0E8CE; } #contactForm { /*border:solid 2px #BFB18F;*/ background:#F0E8CE ; font-family: Verdana, Arial, Helvetica, sans-serif; font-size:12px; text-align: left; } #contactForm h1 { margin-bottom: 5px; font-size:14px; font-weight:bold; color: #546666; } #contactForm p{ font-size:11px; color:#789090; margin-bottom:5px; border-bottom:solid 1px #ffffff; padding-bottom:5px; } #contactForm label{ display:block; font-weight:bold; text-align:right; width:140px; float:left; margin-top: 10; } #contactForm .small{ color:#666666; display:block; font-size:11px; font-weight:normal; text-align:right; width:140px; } #contactForm text { float:left; font-size:12px; padding: 2px 4px; border:solid 1px #aacfe4; width:150px; margin:2px 0 10px 5px; } #contactForm textarea { float:left; font-size:12px; padding: 2px 4px; border:solid 1px #aacfe4; cols: 45; rows: 10; margin:5px 0 10px 5px; } #contactForm radio { float:left; font-size:12px; padding: 2px 4px; border:solid 1px #aacfe4; width:50px; margin:2px 0 10px 5px; } #contactForm button{ width:75px; height:25px; text-align:center; line-height:25px; color:#546666; font-size:12px; font-weight:bold; font-size:12px; padding:0; border:solid 1px #aacfe4; margin:2px 0 5px 0; } </style> <div id="contactUs"> <!-- beginning of the contact us page code --> <div class="Row"><!-- top row--> </div><!--top row--> <div id="leftCol" class="myform"><!-- left column--> <div id="contact"> <form name="ContactUs" class="contactForm"> <label>Full Name <span class="small">first & last</span></label> <input name="fname" type="text" id="fname" tabindex="1" dir="ltr" lang="en" maxlength="65" /> <label>Email Address <span class="small">your@email.com</span></label> <input name="email" type="text" id="email" tabindex="2" dir="ltr" lang="en" maxlength="65" /> <label>Telephone <span class="small">xxx-xxx-xxxx</span></label> <input name="phone" type="text" id="lname" dir="ltr" lang="en" maxlength="12" /> <label>Comments&<span class="small">or questions?</span></label> <textarea name="comments" cols="30" rows="7" tabindex="4"></textarea> <input type='hidden' name='sub' /> <!-- make sure form is posted --> <button type="reset">Clear</button> <button type="submit">Submit</button> </form>
  4. I had a topic just like this, and there were a few replies, this was the best system i found to do it for on my site...depending how large your site is, or how in depth it gets you may need more than this. just copy this code to a blank page and try it out. save the page as pagetest.php and upload it. <?php $p = $_GET['p']; //get the correct page id (p) from the URL switch ($p) { //begin switch, choose the right resulting page data default: //this is the default, so whenever the page is loaded without an id, it displays this echo '<a href="pagetest.php?p=hello"> HELLO</a><BR /><BR />'; echo '<a href="pagetest.php?p=goodbye"> GOODBYE</a><BR /><BR />'; break; case "hello" : //if the id is hello echo 'Hello, and welcome to our page!'; break; case "goodbye" : //if the ?p= is goodbye echo 'Thanks for coming, Goodbye!'; break; } //end switch ?>
  5. I have decided this would be the best route...it's really not a template system but an ease of use system. I want to run the entire page off the index, so having the header and footer added with only 2 lines of code is a big space savings in the index.
  6. yea, my project is small so all im really looking for is how to create a function to load a header, content area, and a footer into my index page so i dont have cluttered code on the main page...is it as simeple as just throwing in a <?php include ('header.php'); ?> where I want my header to be?
  7. too hard to put together for a novice php coder?
  8. thats outta my league...haha. picking out the extra } was just something I noticed right away with the if and while statements. extra set of eyes always helps
  9. im new to PHP but it looks like you have a } in the wrong place. try this... <?php session_start(); require_once('config.php'); $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } $qry="SELECT * FROM members WHERE username='$_SESSION[user];'"; $result=mysql_query($qry); $getbadge = mysql_query($query) or die(mysql_error()); if($result) { while ($row = mysql_fetch_array($getbadge)) { $img = $row['badges']; echo "<img src='badges/".$img.".gif' alt='".$img."'>"; } } else { echo "<p>".$error."</p><br>"; } ?>
  10. Using that wouldn't it be a gigantic file size to include all of the possible cases? I mean. if i had index.php?action=contact and then have the entire contact page code after it? if i had 8 different links at the top and then had 8 different sets of data below it that could possibly be loaded. Is it that involved/difficult to make it call a function like get_contact(); which would load the contents of contact.php and place it into the page for you?
  11. i'm a php beginner, but im 99% that you need to have the actual file saved locally, or be able to open in it an online editor which would mean having direct access to it from the server...
  12. ok so something like this, i was just discussing this in another thread (http://www.phpfreaks.com/forums/index.php/topic,239825.0.html) is this kinda the same scenario?. a user clicks a link, and there's a value passed like 'index.php?action=contact' and you would load the contact data into the page upon reloading? i was thinking of having the same thing for my site to keep are there any examples of this around? and what exactly is this called? how would i search for it say, on Google? does this use an outside functions page and config so that on reload it would call the right function which would load the right page data? am i getting over my head for a beginner with something like this? it doesn't seem all that hard, but im sure it's more than what it looks.
  13. I'm curious how to use a file in all pages on a website without using an include or require line at the beginning of every page...basically i'm looking to have a single index page be template driven, but if the user moves to another page maintain the template, and be able to access any function on any page. kind of like how when using wordpress, you enter the database info into the config file, and no matter what page you are on it can still connect to the database
  14. crayon that looks good, but i have a question...how is the code i posted working correctly? I mean while reading your reply it caught my eye that i have $type in there, but i never defined a $type in the code...does the $_GET['type'] automatically do so, or...?
  15. ok so i went back again after reading your reply blueman387, and came up with this...If i load the page, it displays my links, if i click either link it echo's the right line. as well, if i enter test.php?type=random it echos the links like i wanted it to. now, is this an acceptable way to accomplish this? <?php if (empty ($_GET['type'])) { echo '<a href="register.php?type=tutor">TUTOR</a> or <a href="register.php?type=student">STUDENT</a>'; } elseif (isset($type) && $type="tutor") { echo 'you have chosen tutor'; } elseif ($type == "student") { echo 'you have chosen student'; } ?>
  16. ok something just came to me, and i went ahead and changed the code to this, it now works to display the links, but if i pass a random value it still thinks i have chosen tutor... <?php $type = $_GET['type']; if (isset($type) && $type='tutor') { echo 'you have chosen tutor'; } elseif ($type == "student") { echo 'you have chosen student'; } else { echo '<a href="register.php?type=tutor">TUTOR</a> or <a href="register.php?type=student">STUDENT</a>'; } ?>
  17. ok so i started messing with it and came up with this... <?php $type = $_GET['type']; if (isset($type)) { if ($type == "tutor") { echo 'you have chosen tutor'; } else { if ($type == "student") { echo 'you have chosen student'; } else { echo '<a href="register.php?type=tutor">TUTOR</a> or <a href="register.php?type=student">STUDENT</a>'; } } } ?> the problem however is that it only works if i enter the ?type=tutor if there is no ?type= in the url it dosnt display the 2 links like i want it to. is it a problem with how i set the $type by using the $_GET?
  18. i am a beginner at PHP, so im posting this to ask if this is a no-no, or if this is ok. it's just a snippet but the idea behind it is that user will chose which type of user they are, and the page will load the correct information for that user... <?php if ($_GET['type'] == '') { echo '<a href="register.php?type=tutor">TUTOR</a> or <a href="register.php?type=student">STUDENT</a>'; } elseif ($_GET['type'] == "tutor") { echo 'you have chosen tutor'; } else { echo 'you have chosen student'; }
  19. i have just begun to dabble in php and the first thing i am trying to tackle is getting certain variables available on any page the user visits..must i have (see below) at the top of every file or is there away to make it so that no matter what page the viewer is on the variables defined in test.php are available? is this a session issue, am i getting over my head or...? <?php include('test.php'); ?> thanks for helping a noob
×
×
  • 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.