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
}
FormaL
  • 359
  • 2
  • 5
  • 19
  • Do you want o add a hidden field and redirect based on that value? – Kumar V Jan 08 '14 at 07: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 ) – FormaL Jan 08 '14 at 07:55
  • In your both form, add hidden field under the `` line. So you can get it in controller. – Kumar V Jan 08 '14 at 08:24
  • this i mention in both form first? – FormaL Jan 08 '14 at 08:37
  • So what is the problem?Did you tried Kumar_v's suggesstion? – user2936213 Jan 08 '14 at 08:43
  • i ask this input i mention in form first, then as per your mention below answer i follow , i am very new for php & codeigniter thats why ask again and again sorry. – FormaL Jan 08 '14 at 08:47
  • You are having two `ar_signup.php` and two `ar_thanks.php` views?in both one for english and one for arabic? – user2936213 Jan 08 '14 at 08:52
  • ar_signup.php for user registration & ar_thanks.php after submission a form, and both are in view same as for english i use, en_signup.php & en_thanks.php they are also in view now need to control this form with hidden input in both forms when controller recv ar go on ar_thanks , if recv en go on en_thanks – FormaL Jan 08 '14 at 08:54
  • Check the answer below. – user2936213 Jan 08 '14 at 09:02

2 Answers2

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.

user2936213
  • 1,021
  • 1
  • 8
  • 19
  • `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'); } } } }` – FormaL Jan 08 '14 at 09:08
  • please tell me mistake in this code when i run it shows again create_user link – FormaL Jan 08 '14 at 09:09
  • please wait problem in wamp htaccess so i will check this online any of problem i will update you. – FormaL Jan 08 '14 at 09:23
  • Ok.If this solves your issue dont forget to accept the answer by clicking the checkmark on left :) – user2936213 Jan 08 '14 at 09:24
  • 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](http://giftotravel.pk/landingpage) – FormaL Jan 08 '14 at 09:29
  • you are here my teacher and from you i learn alot and i knew it for answer acceptance for you i will do it now. – FormaL Jan 08 '14 at 09:30
  • Thanks! You want to remove index.php by .htaccess? and what is the problem in this link? – user2936213 Jan 08 '14 at 09:35
  • when you submit the form, url go again to user/create_user but not redirect on ar_thanks.php this is mistake how i rectify. – FormaL Jan 08 '14 at 09:36
  • Have you checked the database is the entry getting inserted? – user2936213 Jan 08 '14 at 09:46
  • in controller add redirect to load view how is it possible ? – FormaL Jan 08 '14 at 10:29
  • on local wamp db update no problem in code but now to add redirect. – FormaL Jan 08 '14 at 10:29
  • instead of `redirect()` i used directly `$this->load->view` – user2936213 Jan 08 '14 at 10:47
  • but when i use this load facing problem in css thats why i ask for redirect. – FormaL Jan 08 '14 at 10:48
  • what is your css problem?this is nothing related to css – user2936213 Jan 08 '14 at 10:50
  • when i use this load view after submission page go on ar_thanks.php white page with no css & images work let me share a screen short.[link](http://i44.tinypic.com/5qsuc.jpg) – FormaL Jan 08 '14 at 10:54
  • for testing i mention link in ar_thanks.php thanks from fahad you can see a text in screen short. – FormaL Jan 08 '14 at 10:55
  • n your `ar_thanks.php` use this ` ` – user2936213 Jan 08 '14 at 10:57
  • superb its work, now i complete working on en side if any of problem i will post , thankyouuuuuuuuuu so very very much i dont have too much repu points so i cannot up the vote for this post! – FormaL Jan 08 '14 at 11:02
  • Its ok! you got it worked thats fine :) and you can upvote since you are having 15 repo :) – user2936213 Jan 08 '14 at 11:03
  • i done ittt yayyyyyyyyyy thankyou so much , because if you not guide & help me out i dont think its possible to sort it out! – FormaL Jan 08 '14 at 12:46
  • everything fixed, now start working for mobile version...huff! – FormaL Jan 08 '14 at 12:58
  • user2936213, Can i share here a complete application for user guidance – FormaL Jan 09 '14 at 06:18
  • Sorry but I didnt understood what you want? – user2936213 Jan 09 '14 at 06:20
  • I ask now the form is ready for languages login and also data submit in dabtabase so i can share complete project code for public guide. – FormaL Jan 09 '14 at 06:38
  • you can share it on github. – user2936213 Jan 09 '14 at 06:58
  • [link](http://stackoverflow.com/questions/21060203/css-html-fixing-of-background-via-css) CSS Fix for website – FormaL Jan 11 '14 at 08:25
  • [link](http://stackoverflow.com/questions/21086233/codeigniter-controller-load-multiple-views) Multi Views In Controller – FormaL Jan 13 '14 at 07:50
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
}
Kumar V
  • 8,810
  • 9
  • 39
  • 58