Forum Moderators: coopster

Message Too Old, No Replies

Line breaks in forms

         

tresmom5

6:46 pm on Sep 24, 2004 (gmt 0)

10+ Year Member



Let's hope I can word this question right. I am getting really frustrated. Ok, I am making a form that when you enter the info the info it goes to another page. They can select as much or as little info as they want to on the form. So when it sends to the next page I want line breaks between all the variables, but if they choose not to select anything for that then I don't want a line break. I just want it skipped. How do I get it not to leave empty spaces on the page if they skip certain variables. I doubt I'm explaining this well.

If you understand my question and can answer it, I certainly would appreciate it.

I hate being so new at this.

Thanks,

Teresa

coopster

7:32 pm on Sep 24, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Check to see if the variable is set and if there is a value, print it out along with a line break. If not, don't print it.
if (isset($_POST)) { 
foreach ($_POST as $key => $value) {
print "$key: $value<br />\n";
}

tresmom5

7:39 pm on Sep 24, 2004 (gmt 0)

10+ Year Member



Wow! This site is so great. Thanks so much for your help. That is exactly what I was looking for.

Teresa

jatar_k

7:41 pm on Sep 24, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> I hate being so new at this.

we were all there, one day it will be like someone flicked on the light, an epiphany of sorts, and it won't be as overwhelming after that.

So I don't exactly know the scenario but I can give you an example of sorts.

The data submitted will be in the $_POST array (assuming it is posted data), so we could loop through the post array and see what happens. We will include our formatting in the echo'ed line so that line breaks will only be inserted if there is data present.

foreach($_POST as $key => $value) {

this will loop through the key/value pairs in the POST array. $key is the name of the variable and $value is the value entered/selected in that form element.

So for our next line we could echo a line unless the value is empty

if (!empty($value)) echo "<p>$key: $value";

you could also exclude certain things that you don't want to display by adding to this if statement, such as the submit button

if (!empty($value) && $key!= 'submit') echo "<p>$key: $value";

id we throw it together

foreach($_POST as $key => $value) { 
if (!empty($value) && $key!= 'submit') echo "<p>$key: $value";
}

let's start with that and see what we get

<added>too slow and long winded it seems ;)