Welcome Guest, Not a member yet? Register   Sign In
Issue with posting to a page with a form
#1

[eluser]Christophe28[/eluser]
Hello,

On the homepage of my website people can enter their email-address and press submit to register. Then they are coming on the actual register page, where the input of the email-address is already set with their giving email-address. But next to the other inputs (like username, password, captcha) I get errors because CodeIgniter thinks the form has already run ...

Does anybody know a work arround for this issue?

Code on homepage:
Code:
<form action="account/register/" method="post">
   <input type="text" name="email_input" value="Email ..." id="welcomeEmailInput" /><br />
   <input type="submit" value="<?=$lang->register?>" id="welcomeEmailSubmit" />
</form>
Code in account/register controller
Code:
$this->form_validation->set_rules('username', 'Username', 'xss_clean|required|min_length[4]|max_length[45]|callback_user_exists');
$this->form_validation->set_rules('email_input', 'Email Address', 'xss_clean|required|min_length[4]|max_length[45]|valid_email');
// ... along with other form validation rules ...

// If form hasn't run, load empty register view    
if($this->form_validation->run() == FALSE) {
  // code to be executed when form hasn't run, but CI thinks the form already ran
}

Thank you! :-)

Christophe
#2

[eluser]pickupman[/eluser]
It looks like you have left out the username input from your homepage form. The way you should be designing this is that the user can register from your homepage, or go to the account/register page directly. Both ways posting to /account/register, should work properly. If form validation fails the register page should be reloaded with fields repopulated. If form validation passes then, validate input and if fails redisplay form, otherwise add user, and redirect to desired page.
#3

[eluser]Christophe28[/eluser]
Hello,

The idea is to create a single input on the homepage where users just have to enter their email address to register. When clicking submit, they come on the actual register page where the email address is already set so they just have to give their username and password to register ...

Christophe
#4

[eluser]pickupman[/eluser]
That really doesn't do any good for the user. Either way, what are the errors? You are posting to that method, so CI will try to run the form. It should fail on attempt from homepage.
#5

[eluser]SitesByJoe[/eluser]
If the signup form on the homepage passes validation save the post info to the user's session. Then populate the fields with your session data if they've been set.

Something quick like:

Code:
// if our session item has a value
if (! empty($this->session->userdata('field_name')))
{
    // use the session data for the form field
    $field_name = $this->session->userdata('field_name');
}
else
{
    // use the form_validation value for the form field
    $field_name = set_value('field_name')
}

// make an array to fill our form input with
$form_values = array(
    'name' => 'field_name',
    'id' => 'field_name'
    'size' => '30',
    'value' => $field_name // get's it's value from above
);

// spit out the form input
echo form_input($form_values);




Theme © iAndrew 2016 - Forum software by © MyBB