Home Ask Login Register

Developers Planet

Your answer is one click away!

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.



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">

Then, validate form like this and print.

function validateForm() {
    // validate your form here

Hope it helps.

Post Status

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


Leave an answer

Quote of the day: live life