Welcome Guest, Not a member yet? Register   Sign In
auto fill a field from input box
#1

[eluser]the_unforgiven[/eluser]
Hi Guys,

I have a input field that when you press submit it opens a form and I want to get the email the customer first enters in the input

Code:
So this is the input I'm talking about so whatever anyone enters in here:

<div id="enq_div">&lt;input type="text" name="email" class="sendbox" value="Enquire..."/&gt;&lt;/div>
     <div id="send_btn_div"><div id="topnav" class="topnav"><a href="contact" class="signin"><span>&lt;input name="submit" type="submit" class="send" value="" /&gt;&lt;/span></div></div>
     &lt;/form&gt;

I want it get the value and then post it to this full form:
Code:
?php echo form_open('contact/send'); ?&gt;
       &lt;?php if (validation_errors()) { ?&gt;
        <div class="error">&lt;?php echo validation_errors(); ?&gt;</div>
       &lt;?php }?&gt;
      &lt;?php
      echo "<p><label for='name'>Name</label><br/>";
      $data = array('name'=>'name','id'=>'name','size'=>25);
      echo form_input($data) ."</p>";

      echo "<p><label for='phone'>Phone</label><br/>";
      $phone = array('name'=>'phone','id'=>'phone','size'=>25);
      echo form_input($phone) ."</p>";

      echo "<p><label for='email'>Email:</label><br/>";
      $email = array('name'=>'email','id'=>'email','size'=>25, 'value' => ''); // So in this value would be what the typed in the fist code above, how does one do this??
      echo form_input($email) ."</p>";

      echo "<p><label for='message'>Requirements/Message:</label><br/>";
      $message = array('name'=>'message','id'=>'message','size'=>25);
      echo form_textarea($message) ."</p>";
      ?&gt;
    
      &lt;input type="submit" name="submit" class="submit" value="Send" /&gt;
      &lt;?php
      echo form_close();
      ?&gt;

Thanks for reading, and any help appreciated.
#2

[eluser]mbrzuzy[/eluser]
You could use flashdata to pass it back and set it in your form.

Code:
$this->session->set_flashdata('email', $this->input->post('email'));

Code:
$email = array('name'=>'email','id'=>'email','size'=>25, 'value' => $this->session->flashdata('email'));
#3

[eluser]the_unforgiven[/eluser]
Yes i did try that previously but its doesn't seem to want to work.
#4

[eluser]CroNiX[/eluser]
When they submit that form, in that controller, grab the post data and send it to another function which passes it to the view.

Hard to tell the data flow from the little code you provided. I don't understand why you have form elements in your anchor (first code). That won't work. Form elements only get sent from within &lt;form&gt;&lt;/form> tags unless you are using javascript or something.
#5

[eluser]the_unforgiven[/eluser]
Hi Chronix, yes i was thinking that and the form elements are wrapped in &lt;form&gt; tags i only showed the part that i need help on rather the whole thing, but &lt;form&gt;&lt;/form> is there. So maybe i'll try what you said
#6

[eluser]CroNiX[/eluser]
Code:
&lt;form action="/some_controller/some_method"&gt;
  &lt;input type="text" name="email" value="" /&gt;
  &lt;input type="submit" name="submit" value="submit" /&gt;
&lt;/form&gt;
Code:
class Some_controller extends CI_Controller {

  public function some_method()
  {
    //grab "email" from first form and send it to the second form
    $data['email'] = $this->input->post('email');

    $this->load->view('some_view', $data);
  }
}
some_view.php
Code:
//grab the $email and display it in the new form
&lt;form action="/some_function/some_other_method" ...blah..your other form&gt;
  &lt;input type="text" name="email" value="&lt;?php echo $email; ?&gt;" /&gt;
  &lt;input type="submit" name="submit" value="submit" /&gt;
&lt;/form&gt;
#7

[eluser]the_unforgiven[/eluser]
Cheers chronix your a legend!
#8

[eluser]CroNiX[/eluser]
Ha! No, I've just been coding in one way or another for over 30 years. Started with BASIC on my dads TRS-80 Model 2 in the early 80s. Think he still has it somewhere...he never tosses anything computer-related Smile He has a 5 MB harddrive that is as big as a modern PC. It was one of the first consumer hd's. Thanks, now I feel old.
#9

[eluser]the_unforgiven[/eluser]
Epic! Some vintage stuff you got there, eBay springs to mind lol
#10

[eluser]the_unforgiven[/eluser]
Chronix - any idea why im getting this:

Severity: Notice

Message: Trying to get property of non-object

Filename: libraries/Form_validation.php

Line Number: 320

Fatal error: Call to a member function load() on a non-object in /Applications/MAMP/htdocs/new/system/libraries/Form_validation.php on line 320




Theme © iAndrew 2016 - Forum software by © MyBB