What should i add to the following code so that it can save button value onclick in php variable and i will send it in the email

Related searches

Actually, i making a form and have many buttons in the form so I want to know that how it can be done whether when I click the button during form submission it will store that button value and after click to the final submit button a mail will send all input field values including button values that I have clicked.

<script type="text/javascript">
$(document).ready(function() {
  $('#frmemail').submit(function(event) {
    $.ajax({
      type: 'POST',
      url: '',
      data: $('#frmemail').serialize(),
      success: function() {
        $('.success').fadeIn(1000)
      }
    });
  });
});
</script>
     <?php
   if (isset($_POST['garden']))
   {
     $but= $_POST['garden'];
   }
 ?>
 <?php
$name = $_POST['form_name'];
$email = $_POST['form_email'];
$message = $_POST['form_msg'];
$garden = $_POST['garden'];
$to = "admin@rsfcrm.com";
$subject = "RIA Emails";
$body = "Name: ".$name."\nEmail: ".$email."\nGarden".$but."\nMessage:".$message;
$headers = "From: ". $email;
    if (mail($to,$subject,$body,$headers))
{echo "<script>window.alert('Successfull!');
    </script>";  
}else
{echo "<script>window.alert('Fialed');
    </script>"; 
}?>    
<div class="container">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section>
  <form enctype="multipart/form-data" id="frmemail" method="post" action="test2">
    <fieldset class="margin-b">
      <legend>Contact Me</legend>
      <label for="form_name">Name:<input name="form_name" type="text" value="" required autofocus ></label>
      <label for="form_email">Email:<input name="form_email" type="email" value=""></label>
      <label for="form_msg">Message:<textarea name="form_msg" rows="5"></textarea></label>
    </fieldset>
    <button type="submit" id="garage" name="garden" value="gardening">button</button>
    <input type="submit" name="submit" id="submit" value="Submit">
  </form>
  </section>
</div>  </body>`

You can use jquery and hidden variable functionality. like on first button click store value in hidden field and on second button click submit form. if you want code then i can paste here

Increment variable value on button click - PHP, I have a form button that I would like to have increment the value of > < input type="button" id="C2" value="test" onclick="<… That code, on the PHP side, is actually only doing this: method="get"> <input type="submit" name=" add" value="add" So really 30 forms worth of data are sent. You can use the PHP mail() function to send an email with PHP and the simplest way to do this is to send a text email when a visitor to your website fills out a form. (Since you're interested in sending email via PHP, we're assuming you have a live website.

<input type='hidden' name='garage_val' id='garage_val' value='' />
<script>
$("#garage").click(function(){
    $("#garage_val").val($(this).val());
});
</script>

PHP and HTML - Manual, The manual page on this topic includes many examples as well. What encoding/ decoding do I need when I pass a value through a form/URL? form, it is possible to use an image instead of the standard submit button with a tag like: So, you'd access these variables like any other described within the section add a note� Example: Pass a Button Value to an Inline Function. Another common use of an inline function is to pass in a button’s value as an argument. This is also very common when using input elements and the onChange event handler. Take a look at the example below. Notice the value e that’s returned from the onClick event handler:

In your form add this input field

<input type='hidden' name='gardening' value='gardening' />

In your Php code

<?php
$gardening= $_POST['gardening'];
echo $gardening;
?>

Jquery

 $('#frmemail').submit(function(event) {
     $.ajax({
          type: 'POST',
          url: 'yourphpfilename.php',
          data: $('#frmemail').serialize(),
          success: function() {
            alert(data)
          }
        });
      });

No jquery click functions are required to do this,this value will be passed along with the form,hope this helps

(Or)

If you wish the value to be passed only on button click use this

Html

<input type='hidden' name='gardening'  class="hidden"/>

Jquery

$("#garage").click(function(e)
{ 
  e.preventDefault();
  $('.hidden').val('gardening');
});

WebD2: Using JavaScript to Show an Alert, In this lesson, you will use JavaScript to display an alert after the web page has loaded Add the following JavaScript code to the <head> section of your web page: In PHP, variable names must start with a $, but that isn't the case in JavaScript The button includes the onclick attribute, which causes the showAlert() to be� Definition and Usage. The value attribute specifies the initial value for a <button> in a <form>. Note: In a form, the button and its value is only submitted if the button itself was used to submit the form.

JavaScript Examples, The best place to add these code samples is either in your Theme's footer section If you would like to display a form based on a single checkbox This example will disable the submit button if "No" is selected for any of the Typically, you can put field values in an HTML field with the field ID shortcodes. PHP - Keep The Values in The Form. To show the values in the input fields after the user hits the submit button, we add a little PHP script inside the value attribute of the following input fields: name, email, and website. In the comment textarea field, we put the script between the <textarea> and </textarea> tags.

Buggy JavaScript Code: The 10 Most Common Mistakes , If you need help figuring out why your JavaScript isn't working, consult this list In most other languages, the code above would lead to an error because the add, modify, and remove elements), but does nothing to promote doing so efficiently. This ensures that each onclick receives and uses the proper i value ( via the� The reason that I broke it up into two pages is so that you could see more clearly what is happenning. You can do it in one page - I just wanted it to be obvious that when the user clicks the button, the data is getting sent back to the web server for the PHP commands to execute.

Following example will send an HTML email message to xyz@somedomain.com copying it to afgh@somedomain.com. You can code this program in such a way that it should receive all content from the user and then it should send an email.

Comments
  • Create a variable that holds values of clicked buttons, then add it to serialized data before posting.
  • can you show me with code because that's not sending value.
  • You would have to add onclick events to buttons that write to the variable, if you want to continue with this approach instead of hidden fields write some code and ask for more help when you have a more specific issue.
  • yeah please, one thing I want to confirm that with the button I don't want it with input type = submit i want it with button type = button
  • now on php side you have to check value for garage_val
  • main thing is that after button click how i will acces that value and send it in mail like php
  • Awesome dear thanks for your cooperation just tell me now how i will send this value in php like: echo $gardening; how i will do it i want to save that value in php variable when a user clicks on that button and i want echo that value in php variable.i hope you got it???
  • @Hsherazch in ajax success:function(data){alert(data)}