1

i made a simple form for users to add email & city for newsletter form is working fine and insert data in db, but i use two form because of english and arabic users now i need to add hidden input on both form secondly i need redirect as per the hidden input what can i do please suggest and guide me to fix this problem, for convenience i share complete codes as files.

ar_signup.php in views

<!DOCTYPE html> 
<html lang="en-US">
  <head>
    <title>Landing Page</title>
    <meta charset="utf-8">
    <link href="assests/css/ar/ar.css" rel="stylesheet" type="text/css">    
  </head>
  <body>        
    <div id="wrapper">
    <div id="columnout" class="left">
        <div id="column">
            <a id="lanLnk" href="http://english.halalat.com" title="english" target="_blank">english</a>  
            <?php echo validation_errors(); ?>
            <?php echo form_open('user/create_user'); ?>                   
                <div class="OptForm">
                    <label>
                        <span style="color:white; font-size: 13pt"><img src="assests/images/ar/email.png" class="opt1">الايميل</img></span>
                        <input id="email" type="text" name="email">
                    </label>
                    <label>
                        <span style="color:white; font-size: 13pt"><img src="assests/images/ar/city.png" class="opt2">المدينة</img>
                        </span>
                        <select name="city" id="city">
                            <option value="jeddah" selected="selected">جدة</option>
                            <option value="riyadh">الرياض</option>
                            <option value="dammam">الدمام</option>
                            <option value="makkah">مكة المكرمة</option>
                            <option value="madina">المدينة</option>

                        </select>
                    </label>
                    <label>
                        <input id="submit-btn" name="Submit" type="submit" class="button" value="Submit">

                    </label>
                </div>
                <?php echo form_close(); ?> <!-- end of Form -->
            <div class="footer_terms">
             <a href="#" target="_blank">تسجيل الدخول</a>
              | <a href="#" target="_blank">سياسة الخصوصية</a>
              | <a href="#" target="_blank">الشروط والأحكام</a>
             </div>
              <div class="social">
             <a href="http://www.facebook.com/halalat" target="_blank"><img src="assests/images/ar/facebook.png" width="48" height="48"></a>
            <a href="http://www.twitter.com/halalatksa" target="_blank"><img src="assests/images/ar/twitter.png" width="48" height="48"></a>
            <a href="#" target="_blank"><img src="assests/images/ar/linkedin.png" width="48" height="48"></a>
            </div>
             <!-- end of Footer -->
            </div><!-- end of Cloumn Left -->
    </div>
    <div id="background-img" style=" margin-top:0; margin-left: auto; margin-right: auto; top:0px; left:0px; padding:0px; right top no-repeat; position:relative; z-index:1;">
     <img src="assests/images/ar/bg_ar2.jpg" width="1181" height="650" alt=""></div>



</div><!-- end of Wrapper -->

  </body>
</html> 

ar_thanks.php in view

    <html>
    <head>
    <meta name="keywords" content="Souq.com,Deal,Day,Best Prices">
    <meta charset="UTF-8">
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
    <title>Halalat Landing Page</title>
    <link href="assests/css/ar/thankyouar.css" rel="stylesheet" type="text/css" media="screen">
    <link href="assests/css/ar/reset.css" rel="stylesheet" type="text/css" media="screen">
    </head>
    <body>
    <div id="wrapper">
        <div id="columnout" class="left">
            <div id="column">
                <a id="lanLnk" href="http://english.halalat.com" title="english" target="_blank">english</a>                        
                <div class="footer_terms">
                 <a href="#" target="_blank">????? ??????</a>
                  | <a href="#" target="_blank">????? ????????</a>
                  | <a href="#" target="_blank">?????? ????????</a>
                 </div>
                  <div class="social">
                 <a href="http://www.facebook.com/halalat" target="_blank"><img src="assests/images/ar/facebook.png" width="48" height="48"></a>
                <a href="http://www.twitter.com/halalatksa" target="_blank"><img src="assests/images/ar/twitter.png" width="48" height="48"></a>
                <a href="#" target="_blank"><img src="assests/images/ar/linkedin.png" width="48" height="48"></a>
                </div>
                 <!-- end of Footer -->
                </div><!-- end of Cloumn Left -->
        </div>
        <div id="background-img" style=" margin-top:0; margin-left: auto; margin-right: auto; top:0px; left:0px; padding:0px; right top no-repeat; position:relative; z-index:1;">
         <img src="./images/bg_ar2.jpg" width="1181" height="650" alt=""></div>



    </div><!-- end of Wrapper -->
    </body>
    </html>

user.php in controller

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

    class User extends CI_Controller {

         function __construct()
         {
           parent::__construct();
         }
    public function create_user()
    {
        // field name, error message, validation rules
                $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
        $this->form_validation->set_rules('city', 'City', 'trim|required');     

        if($this->form_validation->run() == FALSE)
        {
            $this->load->view('ar_signup');
        }
        else
        {           
            $this->load->model('Users_model');

            //if($query = $this->Users_model->create_member())
            {
                $this->load->view('ar_thanks');         
            }

        }

    }
}

users_model.php in model

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    class Users_model extends CI_Model
    {


    function create_member()
    {
            $new_member_insert_data = array(
                'email' => $this->input->post('email'),
                'city' => $this->input->post('city'),                           
            );
            $insert = $this->db->insert('users', $new_member_insert_data);
            return $insert;


    }//create_member
}
9
  • Do you want o add a hidden field and redirect based on that value? Commented Jan 8, 2014 at 7:53
  • i need to add input field in form when the controller get input hidden field redirect the thanks page as per mentioned hidden. 1- Arabic Thanks Page ( ex: hidden input ar ) 2- English Thanks Page ( ex: hidden input en ) Commented Jan 8, 2014 at 7:55
  • In your both form, add hidden field under the <?php echo form_open('user/create_user'); ?> line. So you can get it in controller. Commented Jan 8, 2014 at 8:24
  • <input id="lang" name="ar" type="hidden" value="ar"> this i mention in both form first? Commented Jan 8, 2014 at 8:37
  • So what is the problem?Did you tried Kumar_v's suggesstion? Commented Jan 8, 2014 at 8:43

2 Answers 2

1

In your ar_signup.php form mention <?php echo form_hidden('language', 'ar');?> just after the form_open().
Similarly in en_signup.php form mention <?php echo form_hidden('language', 'en');?> just after the form_open().

Since, as I guess, your both signup forms are redirecting to create_user() function in user controller, just add :

if($this->input->post("language")=="ar")
{
   $this->load->view('ar_thanks');
}
else
{
  $this->load->view('en_thanks');
}

wherever you want to load thanks page.

Sign up to request clarification or add additional context in comments.

27 Comments

public function create_user() { $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email'); $this->form_validation->set_rules('city', 'City', 'trim|required'); if($this->form_validation->run() == FALSE) { $this->load->view('ar_signup'); } else { $this->load->model('Users_model'); if($this->input->post("language")=="ar") { $this->load->view('ar_thanks'); } else { $this->load->view('en_thanks'); } if($query = $this->Users_model->create_member()) { $this->load->view('ar_thanks'); } } } }
please tell me mistake in this code when i run it shows again create_user link
please wait problem in wamp htaccess so i will check this online any of problem i will update you.
Ok.If this solves your issue dont forget to accept the answer by clicking the checkmark on left :)
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php/$0 [PT,L] i mention these lines in httaccess, and now i provide you the link you see still the problem there link
|
0

in your both forms, add hidden field as below.

form_hidden('lang', 'en/ar');

In controller, check lang

if($this->input->post("lang")=='ar')
{
  // redirect to arabic thanks page
}
else
{
   // redirect to english thanks page
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.