rickytenzer Posted March 10, 2008 Share Posted March 10, 2008 Hi fellas, I guess I'd have to say that I'm lower than a newbie, because I really have no experience with PHP. I'm working on my dad's website, which was generally set up by a company for me, and now I'm taking over. We have a consultation form that I've altered quite a bit, and it's working well. I've added in a few validations and such, but now I've hit a roadblock. I added in a verification to make sure that 3 required fields are filled out, that the phone number is 10 digits, and that the email is verified. However, I now realize that if someone gets one of those 3 things wrong after having spent the time to fill out the consultation form, the form will be lost when the hit submit and the page notifies them of the error. I would like to avoid this by somehow storing the selected information in the forms. I'm going to link to the PHP file in a zip file, but please be warned: I'm sure the additions I made are fairly basic and can probably be majorly improved on. Thanks for any help guys! It's really appreciated. http://www.dermamode.com/appointment.zip Quote Link to comment Share on other sites More sharing options...
Perad Posted March 10, 2008 Share Posted March 10, 2008 Redirect the user to the form and set the values as the $_POST[] variables that they just submitted along with an error message. Quote Link to comment Share on other sites More sharing options...
micah1701 Posted March 10, 2008 Share Posted March 10, 2008 set the value of the HTML field like this: <input name="phonenumber" value="<?=htmlspecialchars($_POST['phonenumber']) ?>"> when the page first loads, the field will be blank, but if the page is submitted to itself, the field will be pre-populated with whatever was submitted Quote Link to comment Share on other sites More sharing options...
rickytenzer Posted March 10, 2008 Author Share Posted March 10, 2008 Thanks for replying Perad. However, I'll need a little bit more help than that... Quote Link to comment Share on other sites More sharing options...
rickytenzer Posted March 10, 2008 Author Share Posted March 10, 2008 set the value of the HTML field like this: <input name="phonenumber" value="<?=htmlspecialchars($_POST['phonenumber']) ?>"> when the page first loads, the field will be blank, but if the page is submitted to itself, the field will be pre-populated with whatever was submitted Thanks for replying. I tried that, and it didn't work. When I previewed it in Firefox using Dreamweaver, the "=htmlspecialchars($_POST['phonenumber'])" showed up in the text box. However, when I put the file online and tried it, nothing showed up in the text box at first, but the submitted value didn't show up either when the form returned the error. This is the code: <input name="name" type="text" value="<?=htmlspecialchars($_POST['name'])?>" size="27px"> Where am I going wrong? Quote Link to comment Share on other sites More sharing options...
rickytenzer Posted March 10, 2008 Author Share Posted March 10, 2008 Okay, I've figured out that it's because there is no value set for "name". Can someone please check the beginning of my code to see why it's not set? Quote Link to comment Share on other sites More sharing options...
rickytenzer Posted March 10, 2008 Author Share Posted March 10, 2008 PLEASE! I really need help! Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 10, 2008 Share Posted March 10, 2008 maybe because you never close the <FORM> tag. you need a </FORM> after all form elements. Quote Link to comment Share on other sites More sharing options...
rickytenzer Posted March 10, 2008 Author Share Posted March 10, 2008 maybe because you never close the <FORM> tag. you need a </FORM> after all form elements. Thanks for that. I was hoping that that would be it, but unfortunately it wasn't the solution. Besides, I tried to add an echo for the name to a part of the form that has an actively working echo, but it still didn't work. It appears as if the information is not being stored! Quote Link to comment Share on other sites More sharing options...
uniflare Posted March 10, 2008 Share Posted March 10, 2008 set the value of the HTML field like this: <input name="phonenumber" value="<?=htmlspecialchars($_POST['phonenumber']) ?>"> when the page first loads, the field will be blank, but if the page is submitted to itself, the field will be pre-populated with whatever was submitted hmm try this syntax: <input name="phonenumber" value="<?php echo(htmlspecialchars($_POST['phonenumber'])); ?>"> Quote Link to comment Share on other sites More sharing options...
rickytenzer Posted March 10, 2008 Author Share Posted March 10, 2008 set the value of the HTML field like this: <input name="phonenumber" value="<?=htmlspecialchars($_POST['phonenumber']) ?>"> when the page first loads, the field will be blank, but if the page is submitted to itself, the field will be pre-populated with whatever was submitted hmm try this syntax: <input name="phonenumber" value="<?php echo(htmlspecialchars($_POST['phonenumber'])); ?>"> No luck :'( Quote Link to comment Share on other sites More sharing options...
uniflare Posted March 10, 2008 Share Posted March 10, 2008 ok post some code Quote Link to comment Share on other sites More sharing options...
rickytenzer Posted March 10, 2008 Author Share Posted March 10, 2008 ok post some code It's too big to post. I linked to it in the original post. Would you mind taking a look at it? Quote Link to comment Share on other sites More sharing options...
uniflare Posted March 10, 2008 Share Posted March 10, 2008 try putting "print_r($_POST);" in the page somewhere and look at the resulting source html code. show us what the array is when you submit a form Quote Link to comment Share on other sites More sharing options...
rickytenzer Posted March 10, 2008 Author Share Posted March 10, 2008 try putting "print_r($_POST);" in the page somewhere and look at the resulting source html code. show us what the array is when you submit a form A-HA! I'm getting: "Array()" Quote Link to comment Share on other sites More sharing options...
uniflare Posted March 10, 2008 Share Posted March 10, 2008 hmm change action to $_GET and see if your fields are viewable in the url as a query string. also can you give us the output source html form the script, cheers Quote Link to comment Share on other sites More sharing options...
rickytenzer Posted March 10, 2008 Author Share Posted March 10, 2008 hmm change action to $_GET and see if your fields are viewable in the url as a query string. also can you give us the output source html form the script, cheers The action to $_GET where? And what output source? If you want to see what the page should look like, it's up right now: http://www.dermamode.com/appointment.php Quote Link to comment Share on other sites More sharing options...
uniflare Posted March 10, 2008 Share Posted March 10, 2008 sry i was not clear at all lol http://www.dermamode.com/appointment.php - 404 ERROR NOT FOUND change <form action="..." method="post"> to <form action="..." method="get"> Quote Link to comment Share on other sites More sharing options...
rickytenzer Posted March 10, 2008 Author Share Posted March 10, 2008 sry i was not clear at all lol http://www.dermamode.com/appointment.php - 404 ERROR NOT FOUND change <form action="..." method="post"> to <form action="..." method="get"> http://dermamode.com/en/appointment.php Sorry! And I changed it to "get" and still nothing. Quote Link to comment Share on other sites More sharing options...
uniflare Posted March 11, 2008 Share Posted March 11, 2008 seems to work with my browser... Quote Link to comment Share on other sites More sharing options...
rickytenzer Posted March 11, 2008 Author Share Posted March 11, 2008 Got everything to work! Quote Link to comment Share on other sites More sharing options...
uniflare Posted March 11, 2008 Share Posted March 11, 2008 lol congrats good luck in the future care to share the solution? Quote Link to comment Share on other sites More sharing options...
rickytenzer Posted March 12, 2008 Author Share Posted March 12, 2008 lol congrats good luck in the future care to share the solution? Sure! The problem was that every time the form posted, it posted to the same page but redirected to it at the same time. So it was always losing the information. So I changed: <form action="appointment.php" method=post> to <form action="" method=post> and I removed all the header() tags from the code. Those were there merely to relay the error/success messages and they were stored in the URL as "appointment.php?msg="......"". This also a reason as to why I was confused, because I knew that the error/success messages were being brought over. Only later did I realize that it was merely through the URL. Once I fixed the redirection problem, I was able to store the messages in a variable, and just echo them later on without them having to be in the URL. Quote Link to comment 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.