Newscast Theme offer a lot of options, one of these option is cute AJAX contact form… One of my client wanted add to this form additional checkbox field, so lets do it;)…
Newscast Theme oferuje wiele opcji, jedną z tych opcji jest ładny AJAX’owy formularz kontaktowy… Jeden z moich klientów chciał dodać do tego formularza dodatkowe pole zaznaczania, więc zróbmy to;)…
SOLUTION / ROZWIĄZANIE
1. Open file – „newscast/submit_news.php”
Otwórz plik – „newscast/submit_news.php”
2. Add code there where You want to have checkbox fields:
Dodaj kod tam gdzie chcesz mieć pola zaznaczania:
<p class="mftype" ><label for="typeofcontact">Type of contact: </label><input type="checkbox" value="Flat" name="typeofcontact[]" />Flat <input type="checkbox" value="House" name="typeofcontact[]" />House</p> |
3. Open file – „newscast/send.php”
Otwórz plik – „newscast/send.php”
4. Below declare lines in header of file add:
Poniżej linii deklaracji w nagłówku pliku dodaj:
$the_typeofcontact = $_POST['typeofcontact']; $the_typeofcontact_out = ''; $ctoc = ''; if(!empty($the_typeofcontact)) { $ctoc = count($the_typeofcontact); for($i=0; $i < $ctoc; $i++) { $the_typeofcontact_out .= $the_typeofcontact[$i] . ", "; } } |
5. Add our field to array $already_used, like below:
Dodaj nasze pole do tablicy $already_used, jak poniżej:
$already_used = array('yourname','email','website','message','ajax','myemail','myblogname','typeofcontact','Send'); |
6. Next, print out this what we got, like below:
Następnie, wydrukujmy to co mamy, jak poniżej:
(Type of contact: $the_typeofcontact_out)
$message = "New message from $the_name <br/> Mail: $the_email<br /> Website: $the_website <br /> Type of contact: $the_typeofcontact_out <br /> $attach <br /> Message: $message1 <br />"; |
7. Open file – „newscast/js/custom.js”
Otwórz plik – „newscast/js/custom.js”
8. Find code like below (about line 887):
Znajdź kod jak poniżej (około linii 887):
formElements: form.find('textarea, select, input:text, input[type=hidden]'), |
And replace it with this one code:
I zamień go z tym kodem:
formElements: form.find('textarea, select, input:text, input[type=hidden]').end().form.find( ':checkbox' ).attr( 'checked', 'checked' ).end(), |
9. Save and upload new files.
Zapisz i wgraj nowe pliki.
P.S. Enjoy Your checkbox fields;)