1

Is it possible to submit an email address through a text area of an HTMLpage integrated in ASP.net page and send this to a PHP script that control if is actually a valid email address and send answer back to the ASP page so I can get an alert: VALID or NOT VALID. I have 2 webspeace with two different websites: ASP.net and one in PHP.
The ASP.net page has a Webform in HTML. I would like to use this to send the email to the PHP script. which rune the validation and send back the status to the ASP page that would answer through an alert, "mail valid" or "not valid."

The idea I have is that the script (after the validation control) has to send back an answer throw an URL to the ASP page and the ASP page would "listen"/ "get" this URL as a variable in order to diplay with an alert the result of the PHP SCRIPT

PHP side:

    <form action="http://www.exemple.com/scripts/mailvalidation.php" method="post"        id="webform">

SCRIPT PHP ? (maybe using the PHP FILTER_VALIDATE_EMAIL) ?

ASP.NET ?

Any suggestion=?

bostongeorge
  • 85
  • 2
  • 12

4 Answers4

0

I would suggest, validate email in asp.net. There is lot you can do to validate email in asp.net. Like use Regular Expression - refer this, or use EmailValidator to validate. Also check this link - Email Address Validation for ASP.NET

Following is an example of the above.

<asp:RegularExpressionValidator ID="regexEmailValid" runat="server" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ControlToValidate="tbEmail" ErrorMessage="Invalid Email Format"></asp:RegularExpressionValidator>

But if you are interested to know how to communicate between asp.net and php, then you can check following.

Have php page that accepts email as get request, php page can use FILTER_VALIDATE_EMAIL to validate email or any other custom validation you want to add.

Then use jQuery ajax in asp.net webform to invoke that page with get request and from php page send required message and success handler trap the output , display that to asp.net page.

EDIT

After checking your comment, you need to insert to mysql from asp.net. And that is pretty much doable. You need to have mysql connector for .net and use that library to make CRUD operation. Since answer or actual code snippet is not in scope of current question, i am posting links that will be helpful for you.

Following are some of link -

LINK1 LINK2

Community
  • 1
  • 1
Arindam Nayak
  • 7,346
  • 4
  • 32
  • 48
  • Thank you for the answer. I think I would like to make communicate ASP and PHP because after verify the EMAIL address I have to insert this email in a database which I handle with PHP. or, CAN ASP code insert into a mysql database directly without passing through php? – bostongeorge Oct 23 '14 at 09:22
  • @bostongeorge , updated my answer, have a look. In short it is doable to insert to mysql from asp.net code. – Arindam Nayak Oct 23 '14 at 10:50
0

in php file use:

 <?php 

 if(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
  $msg='valid';      
 }
 else{  $msg='invalid';  }
 $urlVar='email='.$_POST['email'].'&msg='.$msg;
  header("location: hostname/PageName.asp?$urlVar");

then in asp you can use above code and execute your msg in if condition as shown:

if(Request.QueryString("msg") != ' ' && Request.QueryString("email") != ''){

} 

I am not good in asp but hope you get concept to handle it

Fas M
  • 429
  • 2
  • 11
0

I would say if the issue is of passing value from asp to php, then use querystring to pass value from one page to another.

But as far as your comment goes...you can directly use ASP to insert the records in MYSQL without passing through PHP.

YOu can use the following as the reference:

http://www.codeproject.com/Articles/36484/Working-C-code-for-MySql-Stored-Procedures-IN-OUT

Sunil
  • 150
  • 7
0

Sounds like a perfect place to use AJAX. It is independent of the language you use. PHP, ASP.NET, JSP it is all the same. All that is needed is simple JavaScript or Jquery.

In your ASP Page,

<form id="myform">
<input type="email" id="email" name="email" />
<button>Submit</button>
</form>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<script type="application/javascript">
$(document).ready(function(){

var formvars = $("#myform").serialize();

var url = "http://www.example.com/your_page.php?" + formvars;


    $.ajax({
        url: url,
        cache:'false',
        dataType: 'text',
        type:"GET",
        success: function(data){
          //alert( data );
           alert( data );
           if(data =="1")
               alert("VALID");
           else
               alert("IN VALID");

        },
        error: function(data){
          alert('error; '+ eval(error));
        }
       });


 });
</script>

In your php script,

<?php

$email = $_REQUEST["email"]
if($email, FILTER_VALIDATE_EMAIL))
   echo "1";
else
   echo "0";
?>

Good luck.

K Neeraj Lal
  • 6,768
  • 3
  • 24
  • 33