redirect to page

Links for php scripts

Moderators: egami, macek, gesf

Post Reply
jaroslav
New php-forum User
New php-forum User
Posts: 2
Joined: Sun Mar 27, 2022 11:10 am

Hi
I have form in my website, and all php actions are in separate file.

I would like print in div of my website message when my condition form actions file returns true. Something like that

php fie with actions for form :

Code: Select all



      $file_name =    $_FILES['uploaded-file']["name"][$i];  

 	if ($_FILES['uploaded-file']['size'][$i] > $max_size) { 
 	$message =  $file_name .  "is too big";
 	//action here to remember/send   $message value;
 	
 	 header("Location:".$_SERVER[HTTP_REFERER]."#file-size-error");  //redirect to html element
                    die();
 	
 	
 	}
                   
                   

my index page ( I set htaccess to treat html as php)

Code: Select all



                <div id ="file-size-error" class="file-error">

                    <?php
                        if(isset($_POST['message'])){   //print message from $message here
                        echo $_POST['message'];
}
                        ?>
                    
                </div>


User avatar
Michalio
php-forum Fan User
php-forum Fan User
Posts: 102
Joined: Sun Jul 18, 2021 1:33 pm
Location: Poland

Use the session:
https://gist.github.com/PphEight/e535a76955aec432dd4cbbf4b1dc5b54
You can use session_set_message during validating the form data and show the message while generating the page layout
Free coding lessons: https://php-forum.com/phpforum/viewtopic.php?t=29852
Post Reply