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
https://forums.phpfreaks.com/topic/95469-forms-information-post-back/
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

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?

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!

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

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

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

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.