Jump to content

Need a help in code and want to make alert!

- - - - -

  • Please log in to reply
5 replies to this topic

#1
xle_camry

xle_camry

    Programmer

  • Members
  • PipPipPipPip
  • 141 posts
This is my html:

<form action="process.php" method="post" name="contact">

						

<table>

<tr>

<td align="center"><b>Name:</b></td>

<td><input name="first_name" type="text" /></td>	

</tr>

					

<tr>

<td align="center" ><b>*E-mail:</b></td>

<td><input name="email" type="text" /></td>	

</tr>


<tr>

<td align="center"><b>*Letter</b></td>

<td><textarea name="text" rows="10" columns="25"></textarea></td>	

</tr>


<tr>

<td><input name="callback" type="hidden" value="true" /></td></tr>

						

<tr>

<td align="center" colspan="2"><input type="submit" name="submit" value="Send" title="Send" ></td>

</tr>

</table>	

</form>



And this is my process.php:

<?php 


$callback			= $_POST["callback"];




if($callback=="true")

{ 

    $to      = 'mymail@mymail.com'; 

    $subject =  "From forum web site";   

    $message = $_POST['text']; 

    $headers = 'From:'. $_POST["first_name"] . "\r\n" . 

        'E-mail:'. $_POST["email"] . "\r\n" . 

        'X-Mailer: PHP/' . phpversion(); 


    $return = mail($to, $subject, $message, $headers); 

    if($return == true) { 

        $msg = "Message has been sent!";

        echo '<span style="color:blue;">'.$msg.'</span>';

    }  

	

}


?> 


My question is this: Are my source codes correct?
And second question: I want to make alert if E-mail and Letter is not filled. I know it is made in javascript, could anyone post it, exactly to my example? How can I make? Thanks too much guys!

#2
Xdawn90

Xdawn90

    Learning Programmer

  • Members
  • PipPipPip
  • 55 posts
A simple example:

<html>
<head>
<title></title>
[B]<script type="text/javascript">
function validate(){
    if (document.contact.text.value == "" || document.contact.email.value == ""){
        alert("Letter or email is empty");
        return false;
    }
}
</script>[/B]
</head>
<body>
<form action="process.php" method="post" name="contact" [B]onsubmit="return validate();"[/B]>
                        
<table>
<tr>
<td align="center"><b>Name:</b></td>
<td><input name="first_name" type="text" /></td>    
</tr>
                    
<tr>
<td align="center" ><b>*E-mail:</b></td>
<td><input name="email" type="text" /></td>    
</tr>

<tr>
<td align="center"><b>*Letter</b></td>
<td><textarea name="text" rows="10" columns="25"></textarea></td>    
</tr>

<tr>
<td><input name="callback" type="hidden" value="true" /></td></tr>
                        
<tr>
<td align="center" colspan="2"><input type="submit" name="submit" value="Send" title="Send"></td>
</tr>
</table>    
</form>
</body>
</html>
Hope it helps.

#3
xle_camry

xle_camry

    Programmer

  • Members
  • PipPipPipPip
  • 141 posts
Thanks Xdawn90! It worked! Thanks too much.
I want to ask, and what about email checking? For example I typed there inappropriate email.
I want to be there mymail@mymail.com for example, @ symbol. Gramatically correct email there must be.
You understand me I think.

#4
Revolt

Revolt

    Programmer

  • Members
  • PipPipPip
  • 99 posts
A simple search for 'javascript email check' in google could have easily answered your question xle_camry.

Check this out: Check Email Address with JavaScript and Regular Expressions | Marketing Technology Blog

#5
xle_camry

xle_camry

    Programmer

  • Members
  • PipPipPipPip
  • 141 posts
Can you post source code here ?

#6
Revolt

Revolt

    Programmer

  • Members
  • PipPipPip
  • 99 posts
Hmm sure

<script language="javascript">

function checkEmail() {

var email = document.getElementById('emailaddress');

var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

if (!filter.test(email.value)) {

alert('Please provide a valid email address');

email.focus;

return false;

}

}

</script>





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users