Get answers quicker by searching

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Unable to retrieve custom field data from the HTML form
  • Hi

    I have recently added some custom fields to a form (Last Name, Country) but the data isn't syncing properly when the users fill in the form - I can get the First Name and E-mail just fine, but not the custom ones.

    This is what I have in the list:

    Surname [Surname,fallback=] Country [Country,fallback=]

    I have adapted the "Subscribe via AJAX" template available in the API documentation, so I will just insert my changes here.

    This is what I have in my PHP file:

    //POST variables $name = $_POST['name']; $surname = $_POST['surname']; $email = $_POST['email']; $country = $_POST['country'];

    //subscribe $postdata = http_build_query( array( 'name' => $name, 'surname' => $surname, 'email' => $email, 'country' => $country, 'list' => $sendy_list, 'boolean' => 'true' ) );

    This is my HTML form:

    <div class="field-container" style="margin-top: 20px;"> <label for="subscriber-surname" style="line-height: 155%;">Apelido</label><br/> <input type="text" name="surname" id="subscriber-surname" placeholder="Apelido" /> </div> <div class="field-container" style="margin-top: 20px;"> <label for="subscriber-country" style="line-height: 155%;">PaĆ­s</label><br/> <select name="country" id="subscriber-country"> <option value="Portugal" selected>Portugal</option> <option value="Brasil">Brasil</option> <option value="Palop">PALOP</option> <option value="Outro">Outro</option> </select> </div>

    And this is my JavaScript file:

    var jQueryform = jQuery(this), name = jQueryform.find('input[name="name"]').val(), surname = jQueryform.find('input[name="surname"]').val(), email = jQueryform.find('input[name="email"]').val(), country = jQueryform.find('select[name="country"]').val(), url = jQueryform.attr('action'); jQuery.post(url, {name:name, surname:surname, email:email, country:country},

    I believe this is a problem of something being in a different case when it shouldn't, but I can't figure out what I need to change.

    Any help would be greatly appreciated!

    Thank you so much.

    Cheers Bruno

  • 2 Comments
  • Vote Up0Vote Down BenBen
    Posts: 3,507Sendy support

    Hi,

    //subscribe $postdata = http_build_query( array( 'name' => $name, 'surname' => $surname, 'email' => $email, 'country' => $country, 'list' => $sendy_list, 'boolean' => 'true' ) );

    The 'surname' and 'country' in the above line should be 'Surname' and 'Country' respectively as your custom field was created as:

    Surname
    Country

    Your PHP code should match the 'case' of your custom fields.

    Thanks.

    Best regards,
    Ben

  • Hi Ben

    Thank you so much, that worked! :D

    Kind regards Bruno

This discussion has been closed.
All Discussions