0

I want to put 1 variable in my send.php page and get its value by if statement on 2nd (page-contact-us.php)page,
because I have my form in 2nd page with

<form action="<?php bloginfo('template_directory');?>/send.php" method="post" id="contactform">

and in my first page (send.php) i have if statement like,

if($security=="10") {
    mail($to,$subject,$message); 
    $var='1';
}
else {
    $var='2';
}

and on my page-contact-us.php page I want to get this mentioned $var above,
and use this $var value with if else statement like,

if ($var = "1") {

               echo ('<span class="success">Success!</span>');
                }
        else if ($var = "2") {
               echo ('<span class="error">Error!</span>');
            }

How i can achive this ? this is not working for me. :(

3
Contributors
6
Replies
40
Views
3 Years
Discussion Span
Last Post by diafol
2

Use sessions.
If send.php page is independent page (meaning not included by some other page), you have to start session (session_start() function) on the very first line of page code, and than initialize variables as session variables.

// send.php
//on the very begin of page should be started session with session_start(); function

if($security == "10") 
{
    mail($to, $subject, $message); 
    $_SESSION['var'] = $var = '1';
}
    else 
    {
        $_SESSION['var'] = '2';
    }



// page-contact-us.php
// again, on the very top of the page start your session with session_start();

if ($_SESSION['var'] = "1") 
{
    echo ('<span class="success">Success!</span>');
}
    else if ($_SESSION['var'] = "2") 
    {
        echo ('<span class="error">Error!</span>');
    }
0

Wow!!!!!!!
Thank you very so much Bro,
you solved my problem. :) its worked.
but i have 1 little more problem.
when I submmited my form.
it goes to send.php url like this,

/wp-content/themes/ExampleName/send.php

But my original url is this, of wordpress.

example.com/contact-us/

and when it goes to this url there is nothing shows.
and one litle problem is more there that the error msg is not showing on submit button if the form is filled incorrect or,

$security is not =="10"

what is the solution of that?

Edited by ultmt.punisher

0

Action value is showing page that is called with form. If you.
If you want contact-us page after submiting, you'll need to put it in form action. I don't know any other way.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.