Hi guys,
I am pulling my hair out and hope someone can help.
- What I wanted to achieve:
A. If a user submits the CONTACT US form I automatically want to create a Zendesk ticket.
B. The standard field validation and submission SUCCESS or ERROR onscreen message of the standard Webflow form should continue to work.
- What I achieved so far in my test environment:
A submission from the website CONTACT US creates a Zendesk ticket. HURRAY!!!
I achieved that by:
A. renaming the fields in my index.html as follows:
<div class="w-form form-wrapper">
<form id="email-form" method="POST" action="former.php" name="email-form" data-name="Email Form">
<input class="w-input text-field" id="name" type="text" placeholder="Enter your name" name="z_name" data-name="Name" required="required">
<input class="w-input text-field" id="email" type="email" placeholder="Enter your email address" name="z_requester" data-name="Email" required="required">
<input class="w-input text-field" id="Subject" type="text" placeholder="Subject" name="z_subject" data-name="Subject" required="required">
<textarea class="w-input text-area" id="Message" placeholder="Write message" name="z_description" required="required" data-name="Message">
</textarea><input class="w-button newsletter-button" type="submit" value="Submit" data-wait="Busy sending..." wait="Busy sending...">
</form>
<div class="w-form-done success-message">
<p class="success-font">Thank you!
<br>Your submission has been received.</p>
</div>
<div class="w-form-fail error-message">
<p class="error-font">Oops! Something went wrong while submitting the form :(</p>
</div>
</div>
B. Adding an action called: action=“former.php" and
C. Added the PHP file to the server with the following code:
<?php define("ZDAPIKEY", "My Zendesk API Key"); define("ZDUSER", "My Zendesk User Name"); define("ZDURL", "My Zendesk Subdomain"); function curlWrap($url, $json) { $ch = curl_init(); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true ); curl_setopt($ch, CURLOPT_MAXREDIRS, 10 ); curl_setopt($ch, CURLOPT_URL, ZDURL.$url); curl_setopt($ch, CURLOPT_USERPWD, ZDUSER."/token:".ZDAPIKEY); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json')); curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0"); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $output = curl_exec($ch); curl_close($ch); $decoded = json_decode($output); return $decoded; } foreach($_POST as $key => $value) { if(preg_match('/^z_/i',$key)){ $arr[strip_tags($key)] = strip_tags($value);} } $create = json_encode(array('ticket' => array('subject' => $arr['z_subject'], 'comment' => array( "value"=> $arr['z_description']), 'requester' => array('name' => $arr['z_name'], 'email' => $arr['z_requester'])))); $return = curlWrap("/tickets.json", $create); ?>- What does not work:
A. The form does not validate the input anymore, like it did previously.
B. The user does not get the SUCCESS or ERROR confirmation within the CONTACT US section.
C. A new tab will be opened with a blank white page instead of staying on my CONTACT US page with SUCCESS or ERROR message.
It seems like with adding the .php ACTION the form validation does not work anymore.
- QUESTION:
What do I have to do that the form performs all standard Webflow functionalities (validation, SUCCESS ERROR message) when using the PHP Action?
In other words:
A. The fields get validated again.
B. Submission is not possible if the entries are incorrect or incomplete.
C. The user stays on the page section and gets shown the onscreen SUCCESS or ERROR.
I feel I am very close to the final solution as it seems all info is already there.
Thanks in advance.
Cai
Here is my public share link: LINK
(how to access public share link)