Jump to content

tefuzz

Members
  • Posts

    70
  • Joined

  • Last visited

    Never

Everything posted by tefuzz

  1. ok, so if on step 1 i have a field 'name' and i validate it, and now move to step 2 the value of 'name' would be there, since the page had been reloaded only once to validate the $_POST. But would be lost after the visitor submits step 2 correct?
  2. After doing some research on a multiple step form, I have decided to use a single page, and an output according to the step that the user is on. My question is, do the values stay in $_POST even if the page is refreshed and more values are passed through $_POST?
  3. just came in to post that I fixed it, in that exact way...little searching on google got me an answer. thanks
  4. i have this line of code...it gives me a parse error. can you not use an echo in a shortened if statement? <?php (!empty($errors) ? echo "<span class=\"error\">*</span> Errors found, These errors are highlited in <span class=\"error\">red</span>" : null) ?>
  5. I think so too, I just dont know where to start...I have searched google for "php form class" "php form class tutorial" but the results are mixed, and not really anything helpful... ANy tips on where to start?
  6. How hard would creating a form class be? I'm still pretty new to PHP, and i have some rather long forms I need built. I had a smaller contact form I made and just used some IF statements to determine whether to output an error or not, but with the amount of fields i'll be using A class seems like the best option.
  7. I had looked at an AJAX approach, but I figured I'd stick to learning one language at a time...last time i built a website was before CSS came around...only dabbled in since then, and now I'm getting back into it thanks for all the help omzy. i'm going to leave this topic as unsolved until I get it working, that way I can post in here if I have problems (dont forget about me )
  8. and now we've called the form function, and passed trough $errors array as $values. function form1($values) { <input class="text" name="firstname" ', in_array(firstname, $values) ? ' style="background-color: #FFEACE"' : null ,' type="text" value="', isset($_POST[firstname]) ? $_POST[firstname] : null ,'" size="10"/> } so, the function is going to display the input field, this piece of it: in_array(firstname, $values) ? ' style="background-color: #FFEACE"' : null is checking the array, and if firstname is found (referred to as name before, but i know what you meant) '?' thats a shortened 'if' right? so if returns that firstname is present, it will change the background color ( : being the else?) it will return nothing? am i seeing this right? and it does the same for the value of the field, checking if the $_POST was set with this: isset($_POST[firstname]) ? $_POST[firstname] : null , did i get it all?
  9. Ok, I think im getting closer to understanding this... so this piece of code else if($_POST['process'] == 1) { if(strlen($_POST['name']) < 2 || trim($_POST['name']) == '') { $errors[]='name'; } if(!empty($errors)) { form1($errors); } Is First checking to see if "process" is "1". If it IS, then it will begin checking the fields for errors. If name has an error, it adds name to the $errors array then, after the fields are validated, if there are errors found, it runs the form() function passing through the $errors array. right so far?
  10. Omzy, I;m a little confused at that (new to php ) can you elaborate on exactly what that is doing? specifically the second snippet you posted with the <input...
  11. Looking through posts here I have made my way into creating a multiple part form...With some help on code duplication I switched over to using functions to display my form fields, which makes looking at it 100% better. My entire first page of my form only has 66 lines of code instead of the almost 400 I had before...Now comes my dilemma. Sessions seem to be the way to go. I have questions though...I will have 6 parts all together: 4 forms (each on their own page), 1 review/submit page, and 1 thank you page. Where I am having the trouble is the "order" of doing things, and exactly how to accomplish what I am looking for. 1. I would like to validate each step as the 'next' button is pressed, if errors are found I want the page to reload with the good fields filled in and the error fields marked for errors. Should I have a separate "processing" page which will check which step the user is on, and validate the fields accordingly? 2. With the session, if the user hits the back button does the session keep the variables intact? And is there a way to repopulate the fields that were entered? I'll start with those 2 questions. I have already created "step 1" and I am ready to begin the "step 2" but not sure where to start.
  12. actually if i do the following... the ZZZ shows up after the 3 drop down lists... ??? echo (getMonths("month") . " ZZZ " . getDays("day") . " " . getYears("year", "1900", "2009") . "\n</td>\n</tr>");
  13. still learning i have functions that populate drop down lists for my form, i just want non breaking spaces between them...so i used this line echo (getMonths("month") . " " . getDays("day") . " " . getYears("year", "1900", "2009") . "\n</td>\n</tr>"); but it does not echo the spaces, they don't even come up in the page source...actually...4 spaces come up after all the code tat gets created from the function, but nowhere else...the lists show, and the </td> and </tr> are in the page source, but not the spaces...am I thinking too hard for this
  14. I am interested in this as well...I have a form with around 40 fields, and it just looks cluttered on one page...I had thought of breaking it up but wasn't sure how...I'm gonna watch this and see where i goes
  15. Just got to read this now...I believe I see exactly what you mean, and it's exactly what I was looking for. Now, to put it into action and make sure I understand it correctly.
  16. before changing it I went to php.net and checked both mysql_real_escape_string, and strip_tags. since i'm not insterting anything into a database (yet) I went with strip_tags. I guess I should have clarified more. if I insert say < or > into the name or telephone number fields, it returns that they are required. The email field works great, accepting the @ and the . Should it be clearing the entire string? I do not want HTML to be allowed in the email, since it is just a simple contact form. While looking at php.net I found a link to an xss test site with some code to enter in the fields. I used this one: ';alert(String.fromCharCode(88,83,83))//\';alert(String.fromCharCode(88,83,83))//";alert(String.fromCharCode(88,83,83))//\";alert(String.fromCharCode(88,83,83))//--></SCRIPT>">'><SCRIPT>alert(String.fromCharCode(88,83,83))</SCRIPT> doesn't return an error, it returns that the email was sent (when all the other fields were valid) Is this because I allowed the ' to be in the string? I guess the rare occasion where someone has an ' in their name, they will just have to deal with it?
  17. In my contact2.php i changed $fname = $_POST['name']; $ftel = $_POST['phone']; $femail = $_POST['email']; to this: $fname = strip_tags($_POST['name']); $ftel = strip_tags($_POST['phone']); $femail = strip_tags($_POST['email'], '@.'); when I insert some extra characters like your example, it returns the error and shows me that they are required...is that correct
  18. what the?...how did you even do that? ???
  19. Ok, as stated in my previous topics, i am new to PHP. With help from some eBooks and topics here I was able to create a contact page, and an email function. this page can be seen here: http://www.dpserror.com/index.php?p=contact (yes i know the CSS is not complete, haven't hacked it for IE yet) I am using 2 pages to accomplish this, contact.php and contact2.php As you can see, It checks the fields and creates an error array accordingly, then checks to see if the array exists. If it does, it runs a series of if statements to determine which error is present, and echo's the correct snippet of code for each one correct or incorrect. This works great for this small form. My issue now is that I have a form with around 30 different elements I need to validate for a different page, with text boxes, radio buttons, and drop down lists. I was going to use the same type of system to validate it too, but I'm going to end up with what I feel is way too much extra code. Can this be done in PHP or am I looking more at a js or ajax type validation, with PHP as a backup in case javascript is turned off in the browser? The thing I am hung up on is, if I use a function to validate each field, and I return and error, How would I go about creating the error in the right place on the form (getting the same result as I was before). Sorry for the long post, I hope I got all the details about what I am trying to do in here. Thanks in advance for the help. the code for contact.php (just the form section): <div id="contactForm"> <!-- contact form --> <table width="400" border="0" cellpadding="5" 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><label>How should we contact you?<span class="small">phone or email?</span></label></td> <td><input name="prefPhone" type="checkbox" id="prefPhone" label="Telephone" /> <span class="checkLabel">By Telephone <input type="checkbox" name="prefEmail" id="prefEmail" /> By E-Mail</span></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 --> the code for contact2.php: <?php $fname = $_POST['name']; $ftel = $_POST['phone']; $femail = $_POST['email']; if (isset($_POST['prefPhone']) && isset($_POST['prefEmail'])) { // check the checkboxes to see which one(s) are checked $fpref= 'Telephone & E-mail'; // if both are checked = 3 } // if email is checked = 2 elseif (isset($_POST['prefPhone']) && !isset($_POST['prefEmail'])) { // if telephone is checked = 1 $fpref = 'Telephone'; } elseif (!isset($_POST['prefPhone']) && isset($_POST['prefEmail'])) { $fpref = 'E-mail'; } if (empty($fname) or strlen($fname)<3) { $errArray = array('nameError'=>'1'); } if (empty($ftel) or strlen($ftel)<10) { $errArray['telError']='1'; } if (empty($femail) or !preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])' . '(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i', $femail)) { $errArray['emailError']='1'; } if (!isset($errArray)) { if (contactEmail($fname, $femail, $ftel, $fpref, $fcomment)) { echo 'the email was sent succesfully'; } else { echo 'please try to submit your form again'; } } else { echo '<div id="contactUs"> <!-- beginning of the contact us page code --> <div class="Row"><!-- top row--> </div><!--top row--> <div id="leftCol"><!-- left column--> <h1>Contacting us is easy! </h1> <p><br /> If you have questions you can always check out our <a href="index.php?p=faq">"Frequently Asked Questions"</a>. If our FAQ does not get you the answers you need, you can contact us by phone, by mail, or by using our contact form. We respond to each and every inquiry we receive as soon as possible.<br /> </p> <p><br /> If you would like to contact us by telephone, you can call us any time at the number below. If we are unavailable or it is outside normal business hours please be sure to leave a message with your name, telephone number, and the nature of your call. We will respond to your inquiry at our earliest convenience. </p> <br /> Call us at <span class="boldLabel">770-668-6895</span> <p><br /> If you prefer to contact us by mail, you can do so to the following address: </p> <br /> <span class="boldLabel">Mind Garden Tutoring<br /> PO Box 2421<br /> Acworth, GA 30102</span><br /> <br /> </p> </div><!-- left column --> <div id="contactForm"> <!-- contact form --> <table width="400" border="0" cellpadding="5" 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>'; if(isset($errArray['nameError'])) { echo '<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> </tr>'; } else { echo ' <td width="150"><label>Full Name <span class="small">first & last</span></label></td> <td width="250"><input name="name" type="text" id="name" value="' . $fname . '" tabindex="1" dir="ltr" lang="en" maxlength="65" /></td> </tr>'; } if(isset($errArray['emailError'])) { echo '<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" /><span class="smallError">* required</span></td> </tr>'; } else { echo '<tr> <td><label>Email Address <span class="small">your@email.com</span></label></td> <td><input name="email" type="text" value="' . $femail . '" id="email" tabindex="2" dir="ltr" lang="en" maxlength="65" /></td> </tr>'; } if (isset($errArray['telError'])) { echo '<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" /><span class="smallError">* required</span></td> </tr>'; } else { echo '<tr> <td><label>Telephone <span class="small">xxx-xxx-xxxx</span></label></td> <td><input name="phone" type="text" id="phone" value="' . $ftel . '" dir="ltr" lang="en" maxlength=12" /></td> </tr>'; } if (!isset($fpref)) { echo '<tr> <td><label>How should we contact you?<span class="small">phone or email?</span></label></td> <td><input name="prefPhone" type="checkbox" id="prefPhone" label="Telephone" /> <span class="checkLabel">By Telephone <input type="checkbox" name="prefEmail" id="prefEmail" /> By E-Mail</span></td> </tr>'; } if (isset($fpref)) { if ($fpref=='Telephone & E-mail') { echo '<tr> <td><label>How should we contact you?<span class="small">phone or email?</span></label></td> <td><input name="prefPhone" type="checkbox" checked="checked" id="prefPhone" label="Telephone" /> <span class="checkLabel">By Telephone <input type="checkbox" name="prefEmail" checked="checked" id="prefEmail" /> By E-Mail</span></td> </tr>'; } elseif ($fpref=='E-mail') { echo '<tr> <td><label>How should we contact you?<span class="small">phone or email?</span></label></td> <td><input name="prefPhone" type="checkbox" id="prefPhone" label="Telephone" /> <span class="checkLabel">By Telephone <input type="checkbox" name="prefEmail" checked="checked" id="prefEmail" /> By E-Mail</span></td> </tr>'; } elseif ($fpref=='Telephone') { echo '<tr> <td><label>How should we contact you?<span class="small">phone or email?</span></label></td> <td><input name="prefPhone" type="checkbox" checked="checked" id="prefPhone" label="Telephone" /> <span class="checkLabel">By Telephone <input type="checkbox" name="prefEmail" id="prefEmail" /> By E-Mail</span></td> </tr>'; } } if (!isset($fcomment) or strlen($fcomment)==0) { echo '<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>'; } else { echo '<tr> <td valign="top"><label>Comments<span class="small">or questions?</span></label></td> <td><textarea name="comments" cols="30" rows="7" tabindex="4">' . $fcomment . '</textarea></td> </tr>'; } echo' </tr> <tr><td> </td><td><button type="reset">Clear</button> <button type="submit">Submit</button></td> </tr> </form> </table> </div> <!--contact form --> </div> <!--bottom row --> </div> <!-- end of contact us page -->'; } //this is the closing bracket for the IF statement to check whether the $errArray is set ?>
  20. hmm...im gonna have to mess with this and see if i can get that to work. thanks for the link, not sure why i didnt check out that thread when i searched.
×
×
  • 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.