Jump to content

Forms: Information Post-back


rickytenzer

Recommended Posts

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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'])); ?>">

Link to comment
Share on other sites

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  :'(

Link to comment
Share on other sites

lol congrats  ;D

 

good luck in the future  8)

 

 

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.

Link to comment
Share on other sites

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.