Jump to content

RalphLeMouf

Members
  • Posts

    153
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

RalphLeMouf's Achievements

Member

Member (2/5)

0

Reputation

  1. Hey Guys - I have a page that has a jquery modal box that pops up, in that box there is a simple form that prompts the user to submit a name and email. I am trying to stop the page from reloading if there is an error, so the box stays open showing the error. As of now, it closes the box and you have to open the box again to view the error. I am having great trouble implementing the AJAX to my existing code. I am very new to jquery and AJAX and need some major help. I am lost. I've tried a few attempts at adding the AJAX to stop the page from reloading upon error but am just plain confused so I've taken it out. I will show you the code for the jquery and php I have working so far. I just need to add that last function of stopping the page from reloading and keeping the box open until the form is filled out correctly. thanks in advance. if(isset($_POST['submit'])) { $email = $_POST['email']; if(empty($_POST['name']) || empty($_POST['email'])) { $error = "Please enter the info in the fields that are marked <br /> with *"; }elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)){ $error_email = "Please enter a valid email address"; }else{ $success = true; $success = "Thank You"; mysql_query("INSERT INTO watch_list (name, email) VALUES('".$_POST['name']."', '".$_POST['email']."')") or die(mysql_error()); header( 'Location: /watch.php' ); } } <?php if(isset($success)) { ?> <div class="success_watch">Thank You!</div> <?php } ?> <?php if(isset($error)) { ?> <div class="error_watch"> <?php echo $error; ?> </div> <?php } ?> <?php if(isset($error_email)) { ?> <div class="error_watch"> <?php echo $error_email; ?> </div> <?php } ?> <form method="post" action="/index.php"> <div class="form_text_sign_up_required"> All fields marked with an asterisk * are required </div> <div class="form_text_sign_up"> Name* </div> <input type="text" name="name" value="<?php if(isset($_POST['name'])) {echo $_POST['name'];} ?>" /> <br /><br /> <div class="form_text_sign_up"> Email* </div> <input type="text" name="email" value="<?php if(isset($_POST['email'])) { echo $_POST['email'];} ?>" /><br /><br /> <input type='submit' name='submit' value='submit' class='post'/> </form> <script> jQuery(function($) { $("a.topopup").click(function() { loading(); // loading setTimeout(function(){ // then show popup, deley in .5 second loadPopup(); // function show popup }, 500); // .5 second return false; }); /* event for close the popup */ $("div.close").hover( function() { $('span.ecs_tooltip').show(); }, function () { $('span.ecs_tooltip').hide(); } ); $("div.close").click(function() { disablePopup(); // function close pop up }); $(this).keyup(function(event) { if (event.which == 27) { // 27 is 'Ecs' in the keyboard disablePopup(); // function close pop up } }); $("div#backgroundPopup").click(function() { disablePopup(); // function close pop up }); $('a.livebox').click(function() { alert('Hello World!'); return false; }); /************** start: functions. **************/ function loading() { $("div.loader").show(); } function closeloading() { $("div.loader").fadeOut('normal'); } var popupStatus = 0; // set value function loadPopup() { if(popupStatus == 0) { // if value is 0, show popup closeloading(); // fadeout loading $("#toPopup").fadeIn(0500); // fadein popup div $("#backgroundPopup").css("opacity", "0.7"); // css opacity, supports IE7, IE8 $("#backgroundPopup").fadeIn(0001); popupStatus = 1; // and set value to 1 } } function disablePopup() { if(popupStatus == 1) { // if value is 1, close popup $("#toPopup").fadeOut("normal"); $("#backgroundPopup").fadeOut("normal"); popupStatus = 0; // and set value to 0 } } /************** end: functions. **************/ }); // jQuery End </script>
  2. I am having great trouble figuring out how to attach the users id to the url when on their profile. I have read up on uri segments and routes but still can’t figure out how to make it work. here is my controller: public function profile() { $this->load->helper('date'); $this->load->library('session'); $session_id = $this->session->userdata['id']; $this->load->model('account_model'); $user = $this->account_model->user(); $data['user'] = $user; $user['id'] = $this->uri->segment(4); $data['profile_icon'] = 'profile'; $data['main_content'] = 'account/profile/'.$user['id']; $this->load->view('includes/templates/profile_template', $data); } and here is my routes.php file: $route['default_controller'] = "home"; $route['404_override'] = ''; //THIS IS FOR THE VIEW I'M TRYING TO ATTACH THE ID TO $route['profile/([a-z]+)/(\d+)'] = "$1/id_$2"; Thank you in advance
  3. Hey there - I have five required fields in a update query and am inserting them fine. I am very stuck on my birthday dropdown. I had it inserting at one point but when I tried to add validation rules something came undone. Any help is greatly appreciated. Here is a link to my code because it's a lot including the form helper. thanks so much in advance
  4. Hello - I am trying to add a counter that starts with the maximum number of characters a lotted and counts backwards as the user types until they reach their limit. I'm assuming the best way to do this is with jquery keyup, however I have tried A BUNCH of different snippets of jquery and I am not able to integrate it within the codeigniter format. What is the best way to do this with codeiginter? Here is my I am trying to add it to. I would prefer to leave my structure as is and just add what is needed. <div class="edit_section_title"> My Life <br />Tell us a about yourself <span class="edit_sub_text">(1350 character limit)</span> </div> <div class="edit_text_area"> <?php if(empty($user['mylife'])) { echo form_textarea('mylife'); } else { echo form_textarea('mylife', $user['mylife']); } ?> </div> thanks so much in advance
  5. How do I make this ( and my other selectable and text values ) dynamic? Meaning how do I echo the users saved info if filled out or the default values ( even if empty ) if nothing? I have all of my users info ready to go via $user['']
  6. Hello - I am building an edit your profile module on my site right now. When a user signs into their account for the first time after creating it, it takes them to a edit profile page. When a user is already filled out their additional profile information and goes to edit that page, I want to post their already saved info in the pertinent fields and keep them defaulted if untouched. I understand the php logic needed to complete this task, however I was hoping for recommendations or examples on the cleanest way to do this. I will have all the fields per user stored like so: $user['id'], $user['email'] etc... Here is my birthday drop down from my form helper: function month_dropdown($month="month", $top_months=array()) { $months = array( "choose"=>"Month", "----------", "Jan"=>"Jan", "Feb"=>"Feb", "Mar"=>"Mar", "Apr"=>"Apr", "May"=>"May", "Jun"=>"Jun", "Jul"=>"Jul", "Aug"=>"Aug", "Sep"=>"Sep", "Oct"=>"Oct", "Nov"=>"Nov", "Dec"=>"Dec" ); $html = "<select name='{$months}'>"; if(!empty($top_months)){ foreach($top_months as $value){ if(array_key_exists($value, $months)){ $html .="<option value='{$value}'>{$months[$value]}</option>"; } } $html .="<option>----------</option>"; } foreach($months as $key => $month){ $html .="<option value='{$key}'>{$month}</option>"; } $html .="</select>"; return $html; } function day_dropdown($day="day", $top_days=array()) { $days = array( "choose"=>"Day", "----------", "1"=>"1", "2"=>"2", "3"=>"3", "4"=>"4", "5"=>"5", "6"=>"6", "7"=>"7", "8"=>"8", "9"=>"9", "10"=>"10", "11"=>"11", "12"=>"12", "13"=>"13", "14"=>"14", "15"=>"15", "16"=>"16", "17"=>"17", "18"=>"18", "19"=>"19", "20"=>"20", "21"=>"21", "22"=>"22", "23"=>"23", "24"=>"24", "25"=>"25", "26"=>"26", "27"=>"27", "28"=>"28", "29"=>"29", "30"=>"30", "31"=>"31" ); $html = "<select name='{$days}'>"; if(!empty($top_days)){ foreach($top_days as $value){ if(array_key_exists($value, $days)){ $html .="<option value='{$value}'>{$days[$value]}</option>"; } } $html .="<option>----------</option>"; } foreach($days as $key => $day){ $html .="<option value='{$key}'>{$day}</option>"; } $html .="</select>"; return $html; } function year_dropdown($year="year", $top_years=array()) { $years = array( "choose"=>"Year", "----------", "1997"=>"1997", "1996"=>"1996", "1995"=>"1995", "1994"=>"1994", "1993"=>"1993", "1992"=>"1992", "1991"=>"1991", "1990"=>"1990", "1989"=>"1989", "1988"=>"1988", "1987"=>"1987", "1986"=>"1986", "1985"=>"1985", "1984"=>"1984", "1983"=>"1983", "1982"=>"1982", "1981"=>"1981", "1980"=>"1980", "1979"=>"1979", "1978"=>"1978", "1977"=>"1977", "1976"=>"1976", "1975"=>"1975", "1974"=>"1974", "1973"=>"1973", "1972"=>"1972", "1971"=>"1971", "1970"=>"1970", "1969"=>"1969", "1968"=>"1968", "1967"=>"1967", "1966"=>"1966", "1965"=>"1965", "1964"=>"1964", "1963"=>"1963", "1962"=>"1962", "1961"=>"1961", "1960"=>"1960", "1959"=>"1959", "1959"=>"1959", "1958"=>"1958", "1957"=>"1957", "1956"=>"1956", "1955"=>"1955", "1954"=>"1954", "1953"=>"1953", "1953"=>"1953", "1952"=>"1952", "1951"=>"1951", "1950"=>"1950", "1949"=>"1949", "1948"=>"1948", "1947"=>"1947", "1946"=>"1946", "1945"=>"1945", "1944"=>"1944", "1943"=>"1943", "1942"=>"1942", "1941"=>"1941", "1940"=>"1940", "1939"=>"1939", "1938"=>"1938", "1937"=>"1937", "1936"=>"1936", "1935"=>"1935", "1934"=>"1934", "1933"=>"1933", "1932"=>"1932", "1931"=>"1931", "1930"=>"1930" ); $html = "<select name='{$years}'>"; if(!empty($top_years)){ foreach($top_years as $value){ if(array_key_exists($value, $years)){ $html .="<option value='{$value}'>{$years[$value]}</option>"; } } $html .="<option>----------</option>"; } foreach($years as $key => $year){ $html .="<option value='{$key}'>{$year}</option>"; } $html .="</select>"; return $html; } Here is the portion of it in my model in the update query: 'birthday' => $this->input->post('birthday'), Finally, here it is in my view: echo month_dropdown($month)." ".day_dropdown($day). " ".year_dropdown($year); So now what value to do I put in the view portion and model portion to get them to insert properly? Also the original question - How do I add the php to see if something is there or not, and if not there, how do I get the values of existing data to echo? thanks so much in advance
  7. I am trying to create my user module in codeigniter and can't figure out how to pass results from a query in my model to a controller that will allow me to use in my view. Here is my model: public function user() { $session = $this->session->userdata('is_logged_in'); $user_id = $this->session->userdata('id'); $query = $this->db->query("SELECT * FROM users WHERE id=$user_id LIMIT 1"); foreach ($query->result() as $row) { $row->first_name; $row->id; $row->email; $row->last_name; } } and here is my controller. How to do I pass these objects? Or should I be putting them in an array and then passing the array ( still not sure how to pass it ) and then extracting them from the array on my controller? public function edit() { $data['first_name'] = $this->session->userdata('first_name'); $data['profile_icon'] = 'edit'; $data['profile_breadcrumbs'] = 'Edit Profile'; $data['main_content'] = 'account/edit'; $this->load->view('includes/templates/main_page_template', $data); $this->load->library('session'); $this->load->model('account_model'); $session = $this->session->userdata('session_id'); $this->account_model->user(); if($session) { //TRYING TO GET OBJECTS } } thanks in advance
  8. well yeah I did. I tried that code chunk but it's posing errors
  9. Great feedback! I really appreciate it. As I'm still shaky and new with this and code-igniter all together, is there anyway you could re-write what I wrote the way you think it should be? I'm not trying to get you to write my code for me, I just think it would be easier for me to understand what your trying to get across rather than me putting it together based off of your recommendations and being usure of exactly what you mean. thanks
  10. Hey there. I am finalizing all of the errors on my forms. For example, on my login form where the user is prompted to enter their email and password, I have the errors working in order when the password and emails don’t match or it’s not a valid email, BUT if I were to type in an email that is NOT in the database, it only poses error password because it recognizes it as a valid email. I would prefer not to write any new functions if possible and tie it into my existing login function. Here is the model and controller for said module: //MODEL public function validate_home_login($data) { // TAKING THE DATA FROM THE MODEL AND CHECKING IT AGAINST THE STORED INFO IN THE DB $query = $this->db->where($data)->get('users', '1'); if($query->row()) { return $query->row(); $valid_email = $row->email; } } //CONTROLLER public function validate_credentials_login() { $this->load->library('session'); $this->load->helper(array('form','url')); $this->load->model('user_model', 'um'); $this->load->library('encrypt'); $this->load->library('form_validation'); $this->form_validation->set_rules('email_login', 'Email', 'trim|required|valid_email|'); $this->form_validation->set_rules('password_login', 'Password', 'trim|required'); if ( $this->form_validation->run() === TRUE ) { $user = $this->um->validate_home_login(array('email' => $this->input->post('email_login'))); // if $user exists if ( $user ) { // if the password is correct if ( $user->password == $this->encrypt->sha1( $user->salt . $this->encrypt->sha1($this->input->post('password_login'))) && $user->email == $this->input->post('email_login') ) { $this->session->set_userdata(array('email' => $this->input->post('email_login'))); redirect('account/dashboard'); // if the password is incorrect }else{ $this->form_validation->run() == FALSE; $data['password_error'] = 'The password field is invalid.'; } // if $user doesn't exist }else{ $this->form_validation->run() == FALSE; $data['email_error'] = 'This email is invalid.'; } } $data['main_content'] = 'home/home_page'; $this->load->view('includes/templates/home_page_template', $data); } thanks in advance
  11. I am in the process of creating my forgotten password module. My logic seems to be there, but being new with codeigniter and mvc all together I am having some syntax logic errors. The below code is me trying to have the user submit their email address and send them a token email, while simultaneously inserting a unique token and their email in a new table to check when they are actually on the reset password page. I am getting the following errors: ( I get this three times ) A PHP Error was encountered Severity: Notice Message: Trying to get property of non-object Filename: controllers/auth.php Line Number: 150 A PHP Error was encountered Severity: Notice Message: Trying to get property of non-object Filename: controllers/auth.php Line Number: 157 and here is a link to the code thanks in advance.
  12. Hello - I am trying to set up a forgot password system on my site. I am at the first step: which is creating a page where a person enters their email and if the email exists in the database. send them an email with a unique hashed and salted extension to verify security. I have commented out all of my steps and my logic seems to spot on, however my newness to code-igniter I may be accidentally skipping a step or something else? I am using my model to solely query the db and check against what is entered from the user. The errors I am getting are: A PHP Error was encountered Severity: Notice Message: Undefined variable: query Filename: controllers/auth.php Line Number: 142 Fatal error: Call to a member function result() on a non-object in /Users/michaelsanger/Sites/cl_ci_new/application/controllers/auth.php on line 142 however as stated above, what is wrong with my logic? //CONTROLLER function retrieve() // LOADED WHEN THE FORM IS SUBMITTED { $this->load->library('form_validation'); $this->load->library('session'); $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email'); $this->load->model('user_model', 'um'); $this->load->library('encrypt'); $this->load->helper('url'); $submit = $this->input->post('submit'); if($submit) // IF THE SUBMIT BUTTON IS SET { // START PROCESS TO CREATE $USER VARIABLE THAT HOLDS WHAT THE USER ENTERED IN THE FORM AND THAT CAN GET CHECKED AGAINST THE DB IN THE MODEL $user = $this->um->validate_retrieve(array('email' => $this->input->post('email'))); // IF THE USER IS CREATED AND CHECKS OUT AND ALL OF THE ERRORS ARE CLEARED ON THE FORM if( $user && $this->form_validation->run() == TRUE ) { $domain = "clci.dev/index.php"; // CREATE A TOKEN LINK TO SEND TO THE USERS EMAIL THAT EXIST IN THE DB AND WAS ENTERED foreach ($query->result() as $user) $token = sha1($user->email.$user->salt).dechex($user->id); $link = "http://www.".$domain."/account/confirmation/?token=$token"; { $this->load->library('email'); $this->email->from('noreply@cysticlife.org', 'CysticLife'); $this->email->to($user->email); $this->email->subject('Welcome to CysticLife!'); $this->email->message("Thanks for signing up for CysticLife! To complete the registration process please go to the following web address:\n\n$link\n\n-Your friends at CysticLife\n\nPlease remember to add the cysticlife.org domain to your address book to ensure that you receive your CysticLife e-Notifications as requested.eh"); $this->email->send(); redirect('account/welcome'); exit; } } else { $data['main_content'] = 'auth/password'; $this->load->view('includes/templates/main_page_template', $data); } } } //VIEW <div id="forget_pw_form"> <div class="forgotten_pw_text"> Please enter your email address to reset password </div> <?php echo validation_errors(); echo form_open('auth/retrieve'); echo form_label('', 'email', array('type'=>'text')); $data = array( 'name' => 'email', 'class' => 'input', 'placeholder' => 'Email' ); echo form_input($data, set_value('email')); echo form_submit('submit', 'Submit'); echo form_close(); echo "<span class='errors'>"; echo form_error('email'); echo "</span>"; ?> </div> //MODEL function validate_retrieve($data) { $query = $this->db->where($data)->get('users', '1'); if($query->row()) { return $query->row(); } }
  13. Hey guys - I'm trying to implement my captcha helper in code-igniter. I found a tutorial which is a database free method ( which I prefer ) and seems pretty straight forward. I have checked and my GD library is enabled on my server. I am trying to weave it into my create member script and getting undefined variable errors from the view. However I'm pretty sure there is a hole in logic of implementation. function create_member() { $this->load->library('form_validation'); $this->load->library('session'); $this->form_validation->set_rules('first_name', 'First Name', 'trim|required'); $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required'); $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email'); $this->form_validation->set_rules('password', 'Password', 'trim|required'); $this->form_validation->set_rules('password2', 'Confirm Password', 'trim|required|matches[password]'); if($this->input->post() && ($this->input->post('word') == $this->session->userdata('word'))) { if($this->form_validation->run() == FALSE) { $data['main_content'] = 'home/home_page'; $this->load->view('includes/templates/home_page_template', $data); } else { $this->load->model('user_model'); if($query = $this->user_model->create_member()) { $this->load->model('user_model'); $this->varification_email(); $data['main_content'] = 'account/welcome'; $this->load->view('includes/templates/main_page_template', $data); } else { $this->load->view('home/home_page'); } } else { $this->load->helper('captcha'); $vals = array( 'img_path' => './captcha/', 'img_url' => '/captcha/', 'img_width' => '200', 'img_height' => 30, 'border' => 0, 'expiration' => 7200 ); $cap = create_captcha($vals); $data['image'] = $cap['image']; $this->session->set_userdata('word', $cap['word']); $this->load->view('home/home_page'); } echo form_open('auth/create_member'); echo form_label('', 'email', array('type'=>'text')); $data = array( 'name' => 'first_name', 'class' => 'input', 'placeholder' => 'First Name' ); echo form_input($data, set_value('first_name')); echo "<span class='errors'>"; echo form_error('first_name'); echo "</span>"; echo form_label('', 'last_name', array('type'=>'text')); $data = array( 'name' => 'last_name', 'class' => 'input', 'placeholder' => 'Last Name' ); echo form_input($data, set_value('last_name')); echo "<span class='errors'>"; echo form_error('last_name'); echo "</span>"; echo form_label('', 'email', array('type'=>'text')); $data = array( 'name' => 'email', 'class' => 'input', 'placeholder' => 'Email' ); echo form_input($data, set_value('email')); echo "<span class='errors'>"; echo form_error('email'); echo "</span>"; echo form_label('', 'password', array('type'=>'password')); $data = array( 'name' => 'password', 'class' => 'password', 'size' => 30, 'placeholder' => 'Password' ); echo form_password($data, set_value('sha1(password)')); echo "<span class='errors'>"; echo form_error('password'); echo "</span"; echo form_label('', 'password2', array('type'=>'password')); $data = array( 'name' => 'password2', 'class' => 'input', 'size' => 30, 'placeholder' => 'Confirm Password' ); echo form_password($data, set_value('sha1(password2)')); echo "<span class='errors'>"; echo form_error('password2'); echo "</span>"; echo $image; echo form_submit('submit', 'Submit'); echo form_close(); ?> I'm aware of the incompleteness in my view, but that is what I'm having trouble figuring out. How to pass it. Also please not my 'captcha' folder that I have in my root folder is empty and I'm not sure if/or what I should put in there thanks in advance
  14. moreover I'm not sure where to get the library of pics the captcha uses. I was under the impression it was in that library. I am taking a tutorial now on how to implement the captcha, but it starts with him already have the folders filled with the images.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.