FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


[OK] How to force the filling of a email form field ?





Zzz.
Hi there,

I'm tunning my website for a very soon upload and I just need to tweak one detail.

Maybe some of you may explain me how to force the filling of a form field with php (or maybe Javascript is better ? I don't know...) ?

I just wish my users have no choice but to give a valid email before validating any comment posted on my website's articles.

That's not just for fun, fact is that in France, latest laws regarding Electronic Economy and Communications force us, webmasters, to pay high attention on what's posted on our blogs and to keep a kind of tracability in order not to be involved if a user posts unfair stuffs that I eventually did not notice in real time.

Thanks in advance for your help, 'cause i've made a research but found nothing on this forum that could help me to proceed.

Bye Wink
MrBlueSky
Do you want to

1) check whether the field isn't empty?
That can be done with 2 lines of javascript
2) check whether the given email is syntactically correct
That can be done in javascript or PHP with a regular expression
3) check whether the given email is an existing address
That isn't easy, if not impossible.

Please give some more information.
Zzz.
Yep,

I think that for a first shot, I will be likely to verify if the field is or is not empty, if the given adress is or is not an email adress and that will be OK.

Beyond this, I know it's possible to verify if the adress exists, sending a mail to the user and waiting for his reply before doing anything. I've seen such a system at work on a Mailing List software (GMane if my memory doesn't betray me...). I've tried to post on the list, using a web interface, and the system did not validate my message untill I answered to an automatic mail the software has sent to me. The system never asked for my mail to be validated again after. It probably has been saved in a database of authorized mail adresses.

Such a system must be setable on a website I think, but I also don't know how. I'm not really a programmer indeed (soon maybe Wink )
MrBlueSky
Zzz. wrote:
Yep,

I think that for a first shot, I will be likely to verify if the field is or is not empty, if the given adress is or is not an email adress and that will be OK.


Here is an example:

Code:

<HTML>
<BODY>

<SCRIPT type="text/javascript">

function check() {
  var e = document.getElementById("email");
  if (e.value != null && e.value != "") {
    document.getElementById("form1").submit();
    return true;
  }
  alert("Please provide a valid email");
 
}

</SCRIPT>

<FORM action="send.php" id="form1">
  <INPUT id="email">
  <INPUT type="button" onclick="check()" value="Send">
</FORM>

</BODY>
</HTML>




Quote:

Beyond this, I know it's possible to verify if the adress exists, sending a mail to the user and waiting for his reply before doing anything.


That's indeed the way to go when you want to make sure a valid email adress is given.
Zzz.
OK, Thanks for this. In my case, the CMS i'm working with do not record the email adress in the database if a Nickname hasn't been provided too. So in my case, this would be the solution ? Or should I code a different and independant functions for each field ?


Code:
function check() {
  var e = document.getElementById("Nick");
  var f =  document.getElementById("Email");
  if (e.value != null && e.value != "") {
    document.getElementById("form1").submit();
    return true;
  }
  then if (f.value != null && e.value != "") {
    document.getElementById("form1").submit();
    return true;
    }
  alert("Please provide a Nick and a valid Email");
 
}


EDIT : Maybe a moderator could move this thread to the appropriate section ?
sonam
I am prefere PHP.

Code:
<?php
$url = "your_form.html"; //redirect on your form page

$email = $_POST['email'];
$subject= $_POST[subject];
$question = $_POST['question'];

// if is something wrong
if(empty($email) || empty($subject) || empty($question) || !eregi("^[a-z0-9._-]+@+[a-z0-9._-]+\.+[a-z]+$", $email) ) {
      header("Location:http://$url");       exit;
} else {   
// or send mail if is everything ok 
      $to='yourMAIL@yourSITE.com';
      mail($to,$subjekt,$question,"From: $email\r\n"."Reply-To: $email\r\n"); 
      header("Location:http://$url");
      exit;
  }
?>
Zzz.
Hey, thanks for this too. Very Happy

Fact is that, if I'm not thinking wrong, a php script would overide the server with this request, when the javascipt can handle it on the client's side. Now, what's the best in my case ?

I also precise that I don't need this for a Mail Sending form. Just for the forum form, under each of my articles Wink Maybe the sendmail() function beneath is not necessary, then Wink
MrBlueSky
Zzz. wrote:
Hey, thanks for this too. Very Happy

Fact is that, if I'm not thinking wrong, a php script would overide the server with this request, when the javascipt can handle it on the client's side. Now, what's the best in my case ?



Both. The javascript gives direct feedback to the user. But when the user tampers with the form or is doing some trickery to bypass the check (which is easy) the PHP script will detect this.
Zzz.
OK. I've got my stuff then. Thank you very much to both of you Wink
Related topics
Can somebody do me a help?
Simple and Detailed Mail Script
Adding field to message data
neep help making email form that accepts html tags
Email Form
Anyone know how to make an email form?
email form handling on a windows 2000 server help.
ASP.NET 1.0 email form
Anyone need some FRIH$ - for flash email form with PHP
Email form script - 50 FRIH$
Form Processing Email Not Sent
Why is my form field value truncated?
asp.net email form
Looking for an email/attachment form script
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.