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

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

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>

I want it get the value and then post it to this full form:
?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;
      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>";
      &lt;input type="submit" name="submit" class="submit" value="Send" /&gt;
      echo form_close();

Thanks for reading, and any help appreciated.

You could use flashdata to pass it back and set it in your form.

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

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

Yes i did try that previously but its doesn't seem to want to work.

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.

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

&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;
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);
//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;

Cheers chronix your a legend!

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.

Epic! Some vintage stuff you got there, eBay springs to mind lol

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