iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-08-2005, 06:36 AM
WebProWorld Pro
 
Join Date: May 2004
Location: Sydney
Posts: 146
ozchris RepRank 0
Default php form validation of textarea

Hi

I have a problem with php validation and redisplay of textareas in a form.

I have a largish form I'm validating with PHP (still haven't learnt Javascript validation), but as there were only a few fields I cared about I thought I would stick with PHP.

I finally learnt how to call the same page from the form, so that validation is at the top of the page, after checking that the form had been submitted.

$errmsg = "";
if ($_POST['formsubmitted'] == 1) {

/* start form validation */
$valid_form = "1";
$owneremail = $_POST["owneremail"];
$masteremail = $_POST["masteremail"];
etc.


In the form, I needed to redisplay the contents of each field if there had been an error, so I had code like this:
<input type=text name=owneremail value="<? print $owneremail; ?>">

My problem is that when I used textarea, the details were not redisplayed. Is there a different format for redisplaying the textarea fields?

The page is http://www.sydney-web-design.com/fer...ookingform.php

I still haven't finished everything - haven't done W3 validation yet, and there are hiccups, like the Javascript slideshow stops the css menu working in IE, and in Firefox some pictures go beyond the bottom of the page.

I also had fun with sending mail after a valid form. I was testing the mail with a hotmail address hardcoded, and their filter would just completely disregard the mail. I thought the send wasn't working, until I hardcoded it to come from the same domain name. Even adding a CC later to a hotmail address wouldn't work. Or maybe it was a coincidence. And I kept getting php header errors when I used a $headers variable in the mail, so I changed it to the sample below.

mail($to, $subject, $message, "From: $correspondto\n");
header("Location: thankyou.php");


This all seems very cumbersome. Is this really the way people code forms?


Chris
Reply With Quote
  #2 (permalink)  
Old 09-08-2005, 09:02 AM
WebProWorld Pro
 
Join Date: Sep 2005
Location: Manchester, UK
Posts: 254
mikesmith76 RepRank 0
Default

if you want to put the value back in the textarea you need to do something like this:

<textarea name="somename"><?php echo $somevar; ?></textarea>

Thats the way i've always done it and it works fine for me.

Regarding the emailing I think some mail servers disregard emails if they aren't set to be from or to an email address on that server, at least thats what someone told me once.

hope this helps
Reply With Quote
  #3 (permalink)  
Old 09-08-2005, 05:41 PM
WebProWorld Pro
 
Join Date: May 2004
Location: Sydney
Posts: 146
ozchris RepRank 0
Default

Hi Mike,

I'm using print instead of echo, same diff, and it works for all normal input=text fields, but not for the textarea ones.

I Googled, but couldn't find any examples. Maybe it needs col and row variables in the print statement, or something horrible.

I had vaguely heard about the server restriction on emails. But it's rather nasty that it doesn't give a warning - just plain didn't send the email.

It also means that if I wanted to CC the email to an input address, so that the person filling in the form could get a copy of what they had sent, basically can't get it if they aren't on the same server. Or at least not if they have a hotmail address. Pretty crook.

I'll try Yahooing php textarea form redisplay and see what happens.

ta
Reply With Quote
  #4 (permalink)  
Old 09-08-2005, 06:46 PM
WebProWorld Pro
 
Join Date: Sep 2005
Location: Manchester, UK
Posts: 254
mikesmith76 RepRank 0
Default

did you try the code i gave above, that should work

do you get any errors at all when trying it?

mike
Reply With Quote
  #5 (permalink)  
Old 09-08-2005, 08:39 PM
WebProWorld Pro
 
Join Date: Jul 2005
Location: UK
Posts: 166
Steve W RepRank 0
Default

Hi,

Think my 'web design' site's contact page does what you want? Take a look and feel free to submit a few mails to test how it works/blocks errors, no worries :)

The textarea line looks like this:

Code:
<textarea id="message" name="message" cols="40" rows="10" ><?php echo $message; ?></textarea>
If you like how my form works and want the whole code, let me know and I'll post it or pm it or whatever.
Reply With Quote
  #6 (permalink)  
Old 09-08-2005, 09:01 PM
WebProWorld Pro
 
Join Date: May 2004
Location: Sydney
Posts: 146
ozchris RepRank 0
Default

Hi Mike

I hadn't initially noticed the absence of the "value" statement for textarea, so that was a miss.

I tried both echo and print, to no avail.

I also have a test version with less fields at
http://sydney-web-design.com/fergusons/test2.php

The current version there uses this code:
<td><textarea name=owneraddress rows=4 cols=20 <? echo "$owneraddress"?> ></textarea></td>

But still won't redisplay the content.

I even put the same cut-and-pasted code above the form, and the echo worked there - just not inside the textarea.

I'll keep playing..
Reply With Quote
  #7 (permalink)  
Old 09-08-2005, 09:07 PM
WebProWorld Pro
 
Join Date: May 2004
Location: Sydney
Posts: 146
ozchris RepRank 0
Default

Ooh ooh

The > was in the wrong place!

Thanks guys

Chris
Reply With Quote
  #8 (permalink)  
Old 09-09-2005, 04:16 AM
WebProWorld Pro
 
Join Date: Sep 2005
Location: Manchester, UK
Posts: 254
mikesmith76 RepRank 0
Default

no problem glad i could be of help

mike
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 03:59 AM.



Search Engine Optimization by vBSEO 3.3.0