SilverStripe Custom Email Form - jQuery.ajax not passing variables to server

SilverStripe Custom Email Form - jQuery.ajax not passing variables to server

By : Tuhairwe Dwayne Pete
Date : November 22 2020, 02:42 PM
To fix this issue I'm trying to build out a custom email form for a SilverStripe site that's a mix of jQuery, HTML, PHP, and SilverStripe API, and I've been stuck on trying to get the form fields over to the server side. And please, please NO suggestions for form plugins--the form is setup as it is and I am not going to go back and spend hours redoing it. , As Steve noted in the comment:
code :

Share : facebook icon twitter icon
JQuery & AJax: passing data variables with form element

JQuery & AJax: passing data variables with form element

By : PlattBob3
Date : March 29 2020, 07:55 AM
it helps some times I have a form that is populated with dynamic form elements based on a "SecID" variable which identifies which section of the site the user is in. , You could try:
code :
data: 'statusType=' + statusVal + '&otherKey=<%=otherVal%>',
jQuery / JS setting global variables but stuck passing to AJAX custom function

jQuery / JS setting global variables but stuck passing to AJAX custom function

By : sudhiCode
Date : March 29 2020, 07:55 AM
Any of those help Managed to work it out, here is the solution for anyone else wanting to know... just had to call the ajax function which handled the global vars
code :
/* grab completed email when enetred into checkout and add to abandoned cart 

for that session */
function validEmail(v) {
    var r = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return (v.match(r) == null) ? false : true;

// set global variables
var checkoutEmail = "";
var checkoutFirstName = "";
var checkoutLastName = "";

$(document).ready(function() {

    function fireCheckoutAC() {
        $.ceAjax('request', fn_url('ac.email'), {
            method: 'post',
            data: {
                'email': checkoutEmail,
                'firstname': checkoutFirstName,
                'lastname': checkoutLastName
            caching: true
    // function to check email field, validate and save to ac for this customer session
    function checkIt(field) {
        field = $(field);
        var email = field.val();
        var emailError = "<p>The email address in the <b>E-mail</b> field is invalid.</p>";
        var emailInputId = field.attr('id');
        if ($("." + emailInputId + "_error_message").length > 0) {
            $("." + emailInputId + "_error_message").remove();
        if (validEmail(email)) {
            //alert('valid email');
            checkoutEmail = email;
        } else {
            field.after("<span class='" + emailInputId + "_error_message help-inline' ><p>" + emailError + "</p></span>");

    // lets check if the email input was already populated, such as browser auto fill etc.. if so use that and save
    var field = $('#onestepcheckout .ty-billing-email input')[0];
    if ($(field).length > 0) {
        if (field.value) {

    // check email thats inputted and save to ac session for this customer, or if email changed to update
    $('#onestepcheckout .ty-billing-email input').blur(function() {

    // if first name entered lets grab it and add to the ac session for the customer
    var firstname_sel = '#onestepcheckout .ty-billing-first-name input';
    var lastname_sel = '#onestepcheckout .ty-billing-last-name input';

    $(firstname_sel+','+lastname_sel).blur(function() {
        checkoutFirstName = $(firstname_sel).val();
        checkoutLastName = $(lastname_sel).val();

    // lets grab the first name and last name if already in input
    var firstname_sel_pre = $('#onestepcheckout .ty-billing-first-name input')[0];
    var lastname_sel_pre = $('#onestepcheckout .ty-billing-last-name input')[0];
    if ($(firstname_sel_pre).length > 0 || $(lastname_sel_pre).length > 0) {
        if (firstname_sel_pre.value || lastname_sel_pre.value) {
            checkoutFirstName = $(firstname_sel_pre).val();
            checkoutLastName = $(firstname_sel_pre).val();

Validating image file in custom jQuery, AJAX, and PHP form (SilverStripe)

Validating image file in custom jQuery, AJAX, and PHP form (SilverStripe)

By : varley98
Date : March 29 2020, 07:55 AM
I hope this helps . You mentioned that you just stick to JS, HTML, & PHP - that's cool because using the SilverStripe framework is all PHP! Learning how to make a custom form provides greater flexibility over UserForms, so it's handy to add to the ol' utility belt. It sounds like this is a good opportunity to learn something new, which is always fun :)
First and foremost, the tips to things you're missing is easy! There is a vast set of documentation for developers at https://docs.silverstripe.org/
code :
public function contestSubmission() {
  return Form::create(
      TextField::create('firstname', 'First Name'),
      TextField::create('lastname', 'Last Name'),
      EmailField::create('useremail', 'Email'),
      FileField::create('image', 'Image')
      FormAction::create('emailValidEntry', 'Submit Entry')
    RequiredFields::create(array('firstname', 'lastname', 'useremail', 'image'))
public function emailValidEntry($data, $form) {
  $contestEntry = ContestEntrySubmission::create();

  $data['ImageEmail'] = base64_encode(file_get_contents($data['UploadedImage']['tmp_name']));

    'from@address', //from
    'testing@address', //to
    'Contest Entry Submission' //subject

  $form->setMessage('Thank you for your submission!', 'good');

Below is the contest entry submission information: <br /><br />
<strong>First Name:</strong> $FirstName<br />
<strong>Last Name:</strong> $LastName<br />
<strong>Email:</strong> $EmailAddress<br />
<strong>Image File (see attached if not shown here):</strong><img src="$ImageEmail" alt="Submitted Image" />
Sending data from the form to an email with jQuery ajax and redirect to another page with passing POST variables not wor

Sending data from the form to an email with jQuery ajax and redirect to another page with passing POST variables not wor

By : user3222540
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I managed to solve the problem. It turned out later that e-mails were not sent in browsers other than Safari too. The problem was that sometimes the website redirected faster than the email was sent using Ajax (it probably depends on the speed of the Internet connection). I used the .when() and .then() functions. I modified the ajax function in such a way that form data firstly had to be successfully sent to the e-mail and then submitted the form and redirected to the 'thank you' page.
code :
$('#submit_registration').on('click', function(e) {
    if ($('#registration_form').valid()) {
      let formData = $('#registration_form').serialize();
      var checkEmailSent;
          url: ajax.url,
          type: 'POST',
          dataType: 'JSON',
          cache: false,
          data: { 
            action: 'registerFormSendEmail', 
            form_data: formData,
          success: function(res) {
            if (res !== 'sent') {
              alert('Error in sending e-mail.');
              checkEmailSent = false;
      ).then(function() {
        if (checkEmailSent == false) {
          return false;
        } else {
SilverStripe - Pass data from controller to html form through jQuery.ajax

SilverStripe - Pass data from controller to html form through jQuery.ajax

By : 孙之清
Date : March 29 2020, 07:55 AM
wish of those help It might not be the answer you are after, but I'd recommend using a great module for this instead... https://github.com/sheadawson/silverstripe-dependentdropdownfield
This is the example that is offers...
Related Posts Related Posts :
  • PHP MySQL Login Failure
  • can't get file_exists to work
  • Array PHP, Check if exist multiple elements to another array
  • Can array_walk be nested in php?
  • Notice: Use of undefined constant DIR - assumed '_DIR_'
  • Getting a weird 500 error with ajax
  • How can I filter an array of strings to remove elements that are prefixes of other elements?
  • Duplicate entries when assigning custom id to Laravel Model
  • AJAX call not returning php file command
  • How to make "INNER JOIN" sql query based on my requirements
  • Routes by DNS names in Symfony2 project
  • Laravel 5.1 Mysql NULL
  • Why special characters like = or " break PHP regexp when using \b word boundary?
  • Login System with a DB Connection Class don't login. Return with else error for invalid login
  • Laravel 4.2 Simple Session Logic not working
  • PHP : get timezone where time is as specified
  • PHP Override an array on file
  • How to upgrade from drush 7 to drush 8 via Composer
  • Dynamic Modal not displaying in table
  • Can I have multiple sessions at the same in PHP?
  • PHP Multiple Filtering Links
  • PHP - XLSX to CSV adding spaces
  • mySQLi SELECT in PHP with another table's IVs for decrypting table column data
  • Insert Text Field Name or ID as Value in MySQL Column
  • How to record the most common time online of a group of users?
  • Switch from mySQL to mariaDB timestamp messup
  • Generating all 6 character alphanumeric combinations (upper and lower case)
  • PHP: Swap placeholders in string variable for corresponding defined variable values
  • HTTP request failed! with file get contents
  • How can I manipulate include_once string?
  • Database table not created after running plugin:refresh
  • Sphinx Get Word in Result through PHP API
  • Sending xml via soapclient in PHP
  • PHP class extension - skipping the middle class by calling the parent of the parent
  • Save data from contentEditable div with mysqli
  • Generating a PDF with sequential order images FPDF
  • How to make a request with PHPLeague oAuth2 client?
  • MySQL count rows with two duplicate column values
  • How to send a curl request with pem certificate via PHP?
  • Request error when processing form in controller
  • Can't save xml file content in mysql with fopen/fwrite/fclose (php)
  • Read only Title from a page?
  • PHP - make echo permanent and visible to all viewers
  • composer fails on server with redmine installed
  • Using foreach With Variables on Smarty
  • How do you specify single print blocks when looping through a 'for' loop?
  • PHP: $_FILES returns empty
  • Symfony2 associative array in entity
  • How do I log every output from a PHP script from the command line?
  • How to implement this json feed into a database structure?
  • Codeigniter, windows, xampp, how to use htaccess to get rid of trailing slash?
  • How to disable Navbar and footer in Yii2 other layouts
  • Json not encode my Special Character
  • echo if POST length is low
  • Warning: require_once error
  • What is this code meaning...?
  • Send to /dev/null a PHP function "echo" output
  • How to store post details and timestamp in database?
  • php mysql - search a row and concatenate values of every columns to variable string
  • Write a program to get N number of positive non-zero integers, so that the sum and product of these numbers are equal
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co