ali February 2016

window.print function call after form validating form in php

I have a problem, i want to print a a div after form validating and then submitting. Issue is, when call print.window function in submit button, it display print window without validating form fields.

input type="submit" value="Submit" class="button" name="submit" onclick="window.print()">

while the div which to be print is in

if($_POST['submit']) { echo"print div here"; }

Please help.

Thanks

Answers


vaquiceno February 2016

If you want to print something after form validating and then submitting, you are supposed to do it in client side.

You can do something like this:

<form name="myForm" action="action.php" onsubmit="return validateForm()" method="post"> 
    Name: <input type="text" name="fname">
    <input type="submit" value="Submit">
</form>

Then, validate form like this and print.

<script>
function validateForm() {
    // validate your form here
    window.print();
}
</script>

Hope it helps.

Post Status

Asked in February 2016
Viewed 2,639 times
Voted 11
Answered 1 times

Search




Leave an answer