One submit button multiple actions PHP - php

I have a form below which creates a lead on my Insightly CRM:
<form abframeid="iframe.0.2052424988" abineguid="77AFC49A87B39B622E" action="https://xxxxxxx.insight.ly/WebToLead/Create" method="post" name="insightly_web_to_lead">
<input name="formId" type="hidden" value="Wby7PPWJNXwWA==">
<label for="insightly_firstName">Name*: </label> <input id="insightly_FirstName" name="FirstName" required="" style="width: 300px;" type="text"><br>
<label for="insightly_lastName">Surname*: </label><input id="insightly_LastName" name="LastName" required="" style="width: 300px;" type="text"><br>
<label for="email">Email*: </label><input id="insightly_Email" name="email" required="" style="width: 300px;" type="email"><br>
<label for="Description">Message*: </label><textarea id="insightly_Description" name="Description" required="" style="width: 600px; height: 150px;"></textarea>
<input id="insightly_ResponsibleUser" name="ResponsibleUser" type="hidden" value="1125264"><br>
<input id="insightly_LeadSource" name="LeadSource" type="hidden" value="1032448"><br><input type="submit" value="Submit"> </form><p> </p>
I would like the form to create the CRM Lead + a copy of the contents of be sent to my email address + open a thank you page, so I created the insightly_form.php below which I then used to replace the action above.
<?php
include('https://xxxxxxx.insight.ly/WebToLead/Create');
include('MAILTO:myname#mydomain.com');
?>
<?php
header("Location: http://www.mywebsite.com/thank-you");
?>
The PHP scripts run because it opens the thank you page fine, but no copy is sent to my email nor the lead is created. What am I missing?
Anybody can help, please?

'MAILTO:myname#mydomain.com' is a link which will open email apps when user clicked it.
Instead, you should include the php script which will send email.
<?php
include('https://xxxxxxx.insight.ly/WebToLead/Create');
include('send_me_an_email.php');//write a script send_me_an_email.php to send you the email
?>
<?php
header("Location: http://www.mywebsite.com/thank-you");
?>
Also please refer to this page: http://php.net/manual/en/function.mail.php
I think you can use/modify 2nd example as per your needs.

Related

Ajax call on submit refreshing page

Problem
My page seems to be defaulting to my PHP code instead of being handled asynchronously via ajax. As of now, my page just reloads as a blank screen, the input array successfully got passed over to the PHP, which is comforting, but I seem to just be doing something wrong with the ajax.
What I've tried
After viewing this link and this link, I still cant seem to get this figured out.
Current Standing
Here is the HTML:
<form class="cmxform" id="commentForm" method="" action="">
<fieldset>
<legend>Please provide your name, email address (won't be published) and a comment</legend>
<p>
<label for="spinner">How much do you love science? (optional)</label>
<input id="spinner" name="spinner">
</p>
<p>
<label for="cname">Name (required, at least 2 characters)</label>
<input id="cname" name="name" minlength="2" type="text" required>
</p>
<p>
<label for="cemail">E-Mail (required)</label>
<input id="cemail" type="email" name="email" required>
</p>
<p>
<label for="curl">URL (optional)</label>
<input id="curl" type="url" name="url">
</p>
<p>
<label for="aoi">Area of Interest (optional)</label>
<input id="aoi" type="text" name="aoi">
</p>
<p>
<label for="currprobs">Current Problems (optional)</label>
<input id="currprobs" type="text" name="currprobs">
</p>
<p>
<label for="ccomment">Your comment (required)</label>
<textarea id="ccomment" name="comment" required></textarea>
</p>
<p>
<input id="launch" type="submit" value="Submit">
</p>
</fieldset>
</form>
<div id="results"></div>
Here is the javascript:
$(document).ready(function(){
$("#commentForm").submit(function(event){
/*
var formData = {
'name' : $('input[name=name]').val(),
'email' : $('input[name=email]').val(),
};
*/
alert("SUCCESS?");
});
});
PHP code to return a div after the user has been validated:
<?php
$username = isset($_POST['name'])? trim($_POST['name']):'';
$email= isset($_POST['email'])? trim($_POST['email']):'';
echo '<div id=dynamicDiv>
<p>Hello, '.$username.'!</p>
<p>We look forward to contacting you at, '.$email.'</p>
</div>';
?>
Feedback
Any thoughts are appreciated, even intellectual conversation. Code snippets are idea, but I appreciate anything the community is able
Edit 1
I motified the javascript and php to reflect knowledgable input and best practice for PHP and AJAX calls, however the issue still remains.
Edit 2
My goal now is to just get an alert() statement working inside of my javascript, ajax will be the next step.
I think problem is here
$("#results").html = html_i;
You try change to
$("#results").html(html_i);
And in php you should check name and email
$username = isset($_POST['name'])? trim($_POST['name']):'';
$email= isset($_POST['email'])? trim($_POST['email']):'';
You should change input type="submit" to input type="button" and call Ajax on onclick function, Its resolve your problem because submit button submit form and Ajax call pending not reached to 400 state.

PHP Form Redirect to error link

Using HTML form with action = "www.google.com", but it redirect to link including localhost/www.google.com . My example code is for your reference. Please anyone help me.
My Forms as follows :
<form method="POST" action="www.google.com">
<p>
<label for="name">Name:</label>
<input type="text" name="name" id="name">
</p>
<p>
<label for="email">Email:</label>
<input type="email" name="email" id="email">
</p>
<p>
<label for="comments">Comments:</label>
<textarea name="comments" id="comments"></textarea>
</p>
<p>
<input type="submit" name="send" id="send" value="Send Comments">
</p>
</form>
But, the file when click send button, it redirects to
" http://localhost/basic/www.google.com" error page. Can any one suggest me to resolve the issue.
It is not allowed to send POST request directly to google.com. Why do you want to do this? In the action argument you should have own script which can process request from your form.
Replace your form action
From
action="www.google.com"
To actual link
action="https://www.google.com"

Sending information from html form to email

I have a simple form for a website allowing users to send a query/message to my clients email address.
I'm struggling trying to get this working. So far I have managed to find some code (also via stack overflow) that allows the form to send a blank email to the correct address upon submit. I seem to be missing some code or something that makes the submit button pull information from the form to send.
Below is the code I have.
Thanks (PS I have no experience with PHP, only as to alter the code I previously found to get this far).
<?php
mail('chameleonyeadon#gmail.com', $_POST['name'], $_POST['email'], $_POST['number'], $_POST['message']);
?>
<form method="post" action="email.php" enctype="text/plain">
<!-- name-->
<label class="contact__form--label"><em>What is your name?</em><br>
<input type="text" name="name" class="contact__form__inputbox contact__form__inputbox--marg contact__form__inputbox--pad" placeholder="Enter your name here" maxlength="30" required="required"/></label><br>
<!-- email-->
<label class="contact__form--label"><em>Do you have an email address?</em><br>
<input type="email" name="email" class="contact__form__inputbox contact__form__inputbox--marg contact__form__inputbox--pad" placeholder="Enter your email address here" maxlength="50" required="required"/></label><br>
<!-- number-->
<label class="contact__form--label"><em>Can we contact you by phone?</em><br>
<input type="number" name="number" class="contact__form__inputbox contact__form__inputbox--marg contact__form__inputbox--pad" placeholder="Enter a phone number we can use here" maxlength="50" required="required"/></label><br>
<!-- message-->
<label class="contact__form--label"><em>What is your message?</em><br>
<textarea name="message" required="required" class="contact__form__inputbox contact__form__inputbox--marg contact__form__textarea contact__form__inputbox--pad" placeholder="Enter your message here"></textarea></label><br>
<div class="contact__form__btns">
<input type="submit" value="Send" class="btn btn--brdr btn--padding--less">
<input type="reset" value="Clear" class="btn btn--brdr btn--padding--less btn__formpos">
</div>
</form>
First you have to remove action="email.php" since you put PHP code in the same file.
Then, you have to remove enctype="text/plain" to get it works.
See this stackoverflow subject
Finally, it is good to test what was send in PHP before doing mail function in addition to your required verification

inserting a premade email contact form into website

I have very little knowledge of php so I went ahead and used one from css-tricks email forms he set up for free use:http://css-tricks.com/nice-and-simple-contact-form/.
However I am not sure how to put it into the website without breaking the php code. I assume I can't simply just take the code that I want, which is
<div id="contact-area">
<form method="post" action="contactengine.php">
<label for="Name">Name:</label>
<input type="text" name="Name" id="Name" />
<label for="City">City:</label>
<input type="text" name="City" id="City" />
<label for="Email">Email:</label>
<input type="text" name="Email" id="Email" />
<label for="Message">Message:</label><br />
<textarea name="Message" rows="20" cols="20" id="Message"></textarea>
<input type="submit" name="submit" value="Submit" class="submit-button" />
</form>
<div style="clear: both;"></div>
<p>Check out a version of this with SPAM protection.</p>
</div>
and put it into my html page. I tried using an iframe to link the html page into my html page for my website and it worked, but is this method ok?
Yes, you can just place that coding in your HTML page as long as all the webpage and css file's are linked correctly.(e.g. In the same folder as this page with the coding you have now.)
Using an i-frame for this is not a good idea as it can really mess up your pages and submitting your form.

HTML5 form with jQuery doesn't work on Chrome and Opera

I've used the exact files from this tutorial: http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/
The ideea is to submit the form without refreshing, and displaying a nice animation after submission.
But when I try to use the files for my personalised form, the animation doesn't work on Chrome and Opera. Why?
<div id="contact_form">
<form name="contact" method="post" action="">
<p>Hi, my name is</p>
<input type="text" name="name" id="name" class="input" size="20" value="" class="text-input" />
<p> and my email is</p>
<input type="text" name="email" id="email" class="input" size="20" value="" class="text-input"/>
<p>More Random Text.</p>
<textarea name="message" id="message" class="input" onfocus="this.value='';" class="text-input"> ... </textarea>
<input type="submit" name="submit" class="button" id="submit_btn" value="Send" />
</form>
</div>
Everything works ok in this fiddle:
http://jsfiddle.net/CTGa3/2/
Works in Firefox and Chrome. I am not using your php because I don't have access to it. Instead, I am doing a dummy ajax call via jsfiddle, but the result should be the same.
The only thing I could see is that you didn't include the code for runOnLoad. If you include the code, or remove the runOnLoad() call, everything works fine. That piece of code is outdated anyway, because jQuery can do that for us. You just have to move this line:
$("input#name").select().focus();
To the top of your jQuery code block:
http://jsfiddle.net/CTGa3/3/

Categories