Here is the button:

<input class = "preview" type="submit" name = "Preview" value="Peržiūrėti" />

and here is the submit:

$('input.preview').click(function() {
		
		$('form').attr( 'target', '_blank' );
		
		
         	document.myform.submit();
	});

So when I submit with jquery, and try to get with php the data

print_r($_REQUEST['Preview']);

It does not see such index.

But when I change button type to submit and remove javascript code for submitions, then it works. Have you idea, why it works differently when I submit with jquery and what to do?

Recommended Answers

All 2 Replies

//print_r() is to print an array. Preview is NOT an array. 
//You can print the entire $_REQUEST array:
print_r($_REQUEST);

//OR just the Preview item:
echo $_REQUEST['Preview'];

Also, make sure the button is WITHIN the form.

Lastly, if there is more than one form on the page, the first form on the page is likely to be submitted first. I would suggest you give the form in question an id:

<form id="myForm"...>

then use:
$('input.preview').click(function() {
		
		$('#myForm').attr( 'target', '_blank' ).trigger('submit');
         	/* document.myform.submit(); */
	});

WHen I do

echo $_REQUEST['Preview'];

Still get the error

A PHP Error was encountered

Severity: Notice

Message: Undefined index: Preview

Filename: admin_/info_psl.php

Line Number: 235

Also, make sure the button is WITHIN the form.

It is within a form.

Lastly, if there is more than one form on the page

There is only one form in a page.

But, I can live without javascript submission. Just when I submit, I don't validate the form. But in preview its not that catastrophic. When user submits for saving, then he will see the errors if there is any, so he will not be able to save until he does not fix errors.

Edit: thanks for the response ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.