javascript - How can i submit hidden values to php using AJAX -


i trying send values html form php page. here in form have values hidden.and 1 text field value has passed php page.

index.php:

<?php       if ($login->isuserloggedin() == true){           ?>             <div class="panel panel-default">             <div class="panel-heading"><h4>invite friend</h4></div>             <div class="panel-body">                                     <form action="friend-invite.php" method="get">                               <div class="col-md-4 col-lg-4">                   <label class="control-label" for="friend">enter email address</label>                                 <input type="email" class="form-control" name="friendemail" id="friendemail" placeholder="sam@uncle.com" required><br>                                                   <?php                    echo '<input type="hidden" name="invitename" value="'.$_session["user_name"].'">' ;                                    echo '<input type="hidden" name="invite-url" value="'.$_server['request_uri'].'">';                   echo '<input type="hidden" class="invite-product" name="invite-product-name">';                   ?>                   <input type="submit" name="submit" value="invite" class="btn btn-primary">                 </div>                         </form>             <div class="mail-message"></div>             </div>             </div>       <?php        }else{       }?> 

friend-invite.php:

<?php     include('_header.php');     $user_email = $_get['friendemail'];           $invited_by = $_get['invitename'];       $invite_link = $_get['invite-url'];         $product_name = $_get['invite-product-name'];         if (isset($user_email, $invited_by, $invite_link, $product_name)){         sendinvitation($user_email,$invited_by,$invite_link,$product_name);             } else {           echo "are trying nasty??";     }      function sendinvitation($user_email,$invited_by,$invite_link,$product_name)     {         $mail = new phpmailer;         if (email_use_smtp) {             $mail->issmtp();             $mail->smtpauth = email_smtp_auth;             if (defined(email_smtp_encryption)) {                 $mail->smtpsecure = email_smtp_encryption;             }             $mail->host = email_smtp_host;             $mail->username = email_smtp_username;             $mail->password = email_smtp_password;             $mail->port = email_smtp_port;             $mail->ishtml(true);         } else {             $mail->ismail();         }         $mail->from = email_verification_from;         $mail->fromname = $invited_by;         $mail->addaddress($user_email);         $mail->subject = shop_invite;         $link = $invite_link;         $mail->body = $invited_by." ".friend_invite_product."<a href='".$link."'>".$product_name."</a>";                 if(!$mail->send()) {             $this->errors[] = message_verification_mail_not_sent . $mail->errorinfo;             return false;                     } else {                     return true;                     }     } ?> 

ajax function:

$(function () {         $('form').on('submit', function (e) {           e.preventdefault();           $.ajax({             type: 'get',             url: 'invite-friend.php',             data: $('form').serialize(),             success: function () {                 $(".mail-message").html('<div class="alert alert-success"><strong>success!</strong> indicates successful or positive action.</div>');                             }         });     }); }); 

the friend-invite.php page getting values has been passed , check if values has been set, if has been set call php function sendinvitation() parameters. these things happening pretty good.but want through ajax. how can that.

you forgot give hidden fields id:

 echo '<input type="hidden" name="invitename" id="invitename" value="'.$_session["user_name"].'">' ; 

...


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -