Форма при отправке для отображения результата (Имя) на странице благодарности.Php

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Форма при отправке для отображения результата (Имя) на странице благодарности.

Сообщение Anonymous »

Я не уверен, как это сделать правильно: с помощью jQuery или PHP. У меня есть контактная форма, и при отправке формы я хочу, чтобы результаты некоторых полей отображались на странице результатов с благодарностью:
Thank you for entering **YOURNAME**. Blah blah blah

Можно ли этого добиться с помощью простой строки PHP или нужно вызывать через jQuery?




Get Started





First name*

Last name*

Age

Name the celebrity you would most like to meet, and why?*






Thank you! Your local consultant will contact you soon. 'Like' us while you wait for all the latest VIP offers and promotions!


*These are mandatory fields.









Вот часть jquery
/*************************
plugin to manage ajax forms
*************************/
(function( $ ){

var methods = {
init : function( options ) {

return this.each(function(){

var $this = $(this),
data = $this.data('ajaxForm'),
ajaxForm = $('', {
text : $this.attr('title')
});

// If the plugin hasn't been initialized yet
if ( ! data ) {

$(this).data('ajaxForm', {
target : $this,
ajaxForm : ajaxForm
});

//get the spinner, the valid box and the error box
var mySpinner = $this.find('.ajaxFormWait');
var myValid = $this.find('.ajaxFormValid');
var myError = $this.find('.ajaxFormError');
var myBeforeValid = $this.find('.ajaxFormBeforeValid');

myError.hide();
mySpinner.hide();

//add an event to send the form via AJAX
$this.submit(function(){
// get all the inputs into an array.
var $inputs = $this.find(':input:not([type="submit"], [type="button"])');

// not sure if you wanted this, but I thought I'd add it.
// get an associative array of just the values.
var values = {};
$inputs.each(function() {
if (this.type == "radio" || this.type == "checkbox"){
if($(this).is(':checked')){
if(typeof(values[this.name]) === 'undefined'){
values[this.name] = $(this).val();
}else{
values[this.name] += ', '+($(this).val());
}
}
} else
values[this.name] = $(this).val();
});

function defineTheInvalidsFields(fieldsList){
for(var i in fieldsList){
if(fieldsList == 'closestStudio'){
$this.find('[name="'+fieldsList+'"]').parent().addClass('invalid');
}else{
$this.find('[name="'+fieldsList+'"]').addClass('invalid');
}
}
}

//send an AJAX request
$.ajax({
url: $this.attr('action'),
dataType: 'json',
data: values,
beforeSend: function(){
mySpinner.show();
},
success: function(result){
mySpinner.hide();
$this.find('.invalid').removeClass('invalid');

//error management
if(typeof(result.valid) === 'undefined'){

if(result.multipleSend){ //if multiple send
myError.html('Your request is already sent.');
}else if(result.required){ //if fields are required
defineTheInvalidsFields(result.required);
myError.html('The fields in red are required.');
}else if(result.format){ //if the forma is incorrect
defineTheInvalidsFields(result.format);
myError.html('The fields in red have invalid content.');
}else if(result.loginInvalid){
myError.html(result.loginInvalid);
}else{
myError.html('An unknown error occured.');
}
myValid.slideUp(300);
myError.slideDown(300);
}else if(typeof(result.loginUrl) !== 'undefined'){
window.location.href = result.loginUrl;
}else{
if(result.valid || result.valid == 'true'){
if($('#inputFreetrialFitnessFirst').length){
myBeforeValid.slideUp(300);
myError.slideUp(300);
myValid.slideDown(300);
}else{
window.location = '/free-trial-thank-you/';
}
}else{
myError.html('There was an error sending your details. Please try again.');
myValid.slideUp(300);
myError.slideDown(300);
}
}
}
});

return false;
});

//special case for the heardAbout
$('#heardAbout').change(function(){
if($(this).find('option:selected').attr('value') == 'Other'){
$('#otherHeardAbout').slideDown(300);
}else{
$('#otherHeardAbout').slideUp(300);
}
});
}
});
},
destroy : function(){
return this.each(function(){
var $this = $(this),
data = $this.data('ajaxForm');

// Namespacing FTW
$(window).unbind('.ajaxForm');
data.ajaxForm.remove();
$this.removeData('ajaxForm');
})
}
};

$.fn.ajaxForm = function( method ) {

// Method calling logic
if ( methods[method] ) {
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.ajaxForm' );
}

};

})( jQuery );

Форма отправляется на другую страницу. Есть ли способ настроить таргетинг на определенный элемент div и добавить собственное сообщение с именем.
if(result.valid || result.valid == 'true'){
if($('#inputFreetrialFitnessFirst').length){
myBeforeValid.slideUp(300);
myError.slideUp(300);
myValid.slideDown(300);
}else{
window.location = '/free-trial-thank-you/';
}
}else{
myError.html('There was an error sending your details. Please try again.');
myValid.slideUp(300);
myError.slideDown(300);
}
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»