Pecuilar Form Submission Problem With Hidden Fields
Might have to show a bit more than just one line that might not even be where the problem lies.
- Edited
Formu if else komutları arasına alarak çözersin.
if($group == "kontrol"){
echo "içeriği göster veya gönder";
} else {
echo "içeriği gizle ve gönderme";
}
I added more code for you to inspect. I tried to clean it up so you can see it better. Please forgive any mistakes in my cleanup process.
`
$(document).ready(function() {
var $sections = $('.form_section');
function navigateTo(index) {
//Mark the current section with the class 'current'
$sections
.removeClass('current')
.eq(index)
.addClass('current');
//Show only the navigation buttons that make sense for the current section:
$('.form_navigation2 .previous').toggle(index > 0);
var atTheEnd = index >= $sections.length - 1;
$('.form_navigation1 .signup_now_button').toggle(!atTheEnd);
$('.form_navigation2 [type=submit]').toggle(atTheEnd);
}
function curIndex() {
//Return the current index by looking at which section has the class 'current'
return $sections.index($sections.filter('.current'));
}
$('.form_navigation2 .previous').click(function() {
navigateTo(curIndex() - 1);
$('#the_form').reset;
$('.form_navigation1 .submit_button').click(function() {
$('#the_form').parsley().whenValidate({
group: 'block-' + curIndex()
}).done(function() {
navigateTo(curIndex() + 1);
});
if ($('.part1').val() == 'option1') {
$('.group2,.group3,.group5').hide();
}
if ($('.part2').val() == 'option2') {
$('.group1,.group2,.group5').hide();
}
//Prepare sections by setting the data-parsley-group
attribute to 'block-0', 'block-1', etc.
$sections.each(function(index, section) {
$(section).find(':input').attr('data-parsley-group', 'block-' + index);
});
navigateTo(0); //Start at the beginning
});
`
Weedpacket
I added more code for you to inspect. I am not sure if the problem lies elsewhere. But certainly removing what is hidden (grayed out) works.
thanks
- Edited
ke-jo
I added more code for you to inspect. I tried to clean it up so you can see it better. Please forgive any mistakes in my cleanup process.
`$(document).ready(function() {
var $sections = $('.form_section');
function navigateTo(index) {
//Mark the current section with the class 'current'
$sections
.removeClass('current')
.eq(index)
.addClass('current');
//Show only the navigation buttons that make sense for the current section:
$('.form_navigation2 .previous').toggle(index > 0);
var atTheEnd = index >= $sections.length - 1;
$('.form_navigation1 .submit_button').toggle(!atTheEnd);
$('.form_navigation2 [type=submit]').toggle(atTheEnd);
}
function curIndex() {
//Return the current index by looking at which section has the class 'current'
return $sections.index($sections.filter('.current'));
}
$('.form_navigation2 .previous').click(function() {
navigateTo(curIndex() - 1);
$('#the_form').reset;
$('.form_navigation1 .submit_button').click(function() {
$('#the_form').parsley().whenValidate({
group: 'block-' + curIndex()
}).done(function() {
navigateTo(curIndex() + 1);
});
if ($('.part1').val() == 'option1') {
$('.group2,.group3,.group5').hide();
}
if ($('.part2').val() == 'option2') {
$('.group1,.group2,.group5').hide();
}
//Prepare sections by setting the `data-parsley-group` attribute to 'block-0', 'block-1', etc.
$sections.each(function(index, section) {
$(section).find(':input').attr('data-parsley-group', 'block-' + index);
});
navigateTo(0); //Start at the beginning
});`
- Edited
So at the end there you attach a handler to the form submit button's "click" event, and the handler returns a falsy value (undefined
, because there is no return statement). It's been too long since I've done jQuery to know if that cancels event propagation and stops the event from reaching the submit button's submit handler.
Also this part:
$('.form_navigation2 .previous').click(function() {
navigateTo(curIndex() - 1);
$('#the_form').reset;
looks incomplete. the last line doesn't look like it does anything (should it be reset()
?) and there's no closing });
to separate it from the next part.
- Edited
Weedpacket
Thanks for your help. The reset works fine. The issue is either:
- Make the form "submit" with .show()/.hide() functions being used. or
- Find a way to remove HTML blocks of code and REPLACE them completely on click if user decides to go back by pressing reset.
Both directions can fix the problem if a solution is found for either of these two issues.
The last parenthesis and curly braces are missing here. I am unable to add them in the code here, but they are present and working in original code.
Thanks
What about the first part of what I wrote?
- Edited
Weedpacket
Yes, thanks. Even if I use a "return true;" statement it does not correct the issues of removing and replacing the HTML code blocks. Nor does it submit the form if I am using "show()/hide() functions. The form will only submit if there are no hidden inputs in the chunks of code that are hidden. It still appears to need a fix for the hidden HTML. I even tried to ".clone()" the chunk of HTML before it was remove to restore it later. However, it appears that if the original chunk of code is ".removed()" the clone does not work.
I have a third option of using the ".remove()" to remove all the HTML blocks then replacing it as a very long single string using innerHTML. But I need a way to place some <?php echo something?> into the very long string without the HTML block having issues. Do you know how to place <?php?> into an HTML string without issues?
Thanks