Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    May 2013
    Posts
    22
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Enter an email and submit to 2 diferent pages without user seeing it

    Hey there,

    I have the following problem. I want to design a simple form that sends the site entered into 2 diferent sectors.
    One for sales the other to marketing. Any solution?

    Here is the procedure, the client visit the site and enter in the form his email then this email is convert into a variable using jquery and then is submit to 2 php pages that handles the submission.

    What i'm looking for here is a simple way to make a post submission for 2 php files using plain html + javascript but without showing to user the html page.

    Example:
    Code:
    <form action="sales.php">
    <input type="text" name="email" value="'+client_email+'">
    <input type="button" name="submit" value="Submit"
    </form>
    
    <form action="marketing.php">
    <input type="text" name="email" value="'+client_email+'">
    <input type="button" name="submit" value="Submit"
    </form>

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    You can use AJAX methods provided by jQuery.

    Code:
    // This will send the content of the variable "email" to both scripts without showing the script's outputs
    function sendEmail() {
      var email = $('[name=email]').val();
      $.ajax({
        url : 'sales.php',
        type: "POST",
        data: {email:email},
        success: function() {}
      });
      $.ajax({
        url : 'marketing.php',
        type: "POST",
        data: {email:email},
        success: function() {}
      });
    }
    This example uses the POST method, so on PHP side you can access those values using $_POST[]. If you want to use GET, you'll have to replace the "type" options in the $.ajax calls.

    You only need one form for this. This form doesn't need an action attribute. You can use the submit button to submit the value using Ajax:

    Code:
    $('[name=submit]').submit(function() {
       sendEmail();
       return false;  // this prevents the browser submit (which would show the resulting HTML)
    });

  • Users who have thanked devnull69 for this post:

    Electrify (10-25-2013)

  • #3
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,763
    Thanks
    23
    Thanked 548 Times in 547 Posts
    You could just have the form send dtat to one php file and have that file send the two sectors(?) the same information.
    Evolution - The non-random survival of random variants.

  • #4
    New Coder
    Join Date
    May 2013
    Posts
    22
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Thanks devnull69,

    I didn't implement the code yet until i fully comfortable with the code but my boss want to add an extra element to the request

    Code:
    <input type="hidden" name="SiteCommingFrom" value="homepage">
    How do i add to the $.ajax, add another field Data or add after the comma

    Thanks

  • #5
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    If there are named fields (i.e. input or textarea elements with name attribute) inside a form with id attribute (e.g. id="myform") and you want to send the content of all those fields, you can use .serialize() which will do the job and prepare the parameters to be sent to the server script
    Code:
    function sendEmail() {
      var theData = $('#myform').serialize();
      $.ajax({
        url : 'sales.php',
        type: "POST",
        data: theData,
        success: function() {}
      });
      $.ajax({
        url : 'marketing.php',
        type: "POST",
        data: theData,
        success: function() {}
      });
    }

  • Users who have thanked devnull69 for this post:

    Electrify (11-22-2013)

  • #6
    New Coder
    Join Date
    May 2013
    Posts
    22
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question

    Thanks,

    There is a bug i couldn't fix, multiple parameters in the data.

    Is it all serialized?


    var Parameter1 = $('#fullname').serialize();
    var Parameter2 = $('#pw').serialize();
    var Parameter3 = $('#pw-conf').serialize();
    var Parameter4 = $('#language').serialize();
    var Parameter5 = $('#digest').serialize();
    var Parameter6 = $('#email-button').serialize();


    The Ajax push


    $.ajax({
    url : 'http://127.0.0.1/marketing.php',
    type: "GET",
    data: {email:email},
    data: Parameter1,
    data: Parameter2,
    data: Parameter3,
    data: Parameter4,
    data: Parameter5,
    data: Parameter6,
    success: function() {}
    });
    Last edited by Electrify; 11-22-2013 at 03:00 PM.

  • #7
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    .serialize() is a method for the <form> rather than the input elements. So if you call .serialize() on the form element, you will get one single string containing the key/value-pairs for all the input elements inside the form. You then use this string for the "data" option of $.ajax()


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •