I have a funny thing going on with my local dev setup. Using codeigniter I have a form that should simulate storing some info from a user in a database. At this point I don't have the database setup yet I just want the form to send me to the success page when the validation is complete. But when I submit the form it comes back and tells me that the name field is empty and I never get the success page. Am i missing something here? please look this up and tell me if I am missing something! this is the function in the controller that processes the form.
function showsupport()
{
$this->form_validation->set_rules('supportername','Name','trim|required|max_length[30]');
$this->form_validation->set_rules('supporteremail','Email Address','trim|required|valid_email');
$this->form_validation->set_rules('pledgedate','Pledge Date','trim|required');
$this->form_validation->set_rules('messagetxt','Your Message','trim|required|xss_clean');
if($this->form_validation->run() == FALSE)
{
$this->template->write_view('content','supportus');
$this->template->render();
} else {
$this->template->write('content','Your submission was a success');
$this->template->render();
}
}
<div id="supportform" class="formblock">
<?php
$formdata = array('id'=>'suppform');
echo form_open('homepage/showsupport',$formdata);
$namedata = array('name'=>'supportname','id'=>'supportname','size'=>'30','max_length'=>'25');
echo '<label for="supportername">Your Name:'.form_input($namedata,set_value('supportname')).'</label><br /><br />';
$emaildata = array('name'=&g开发者_如何学Pythont;'supporteremail','id'=>'supporteremail','size'=>'30','max_lenth'=>'25');
echo '<label for="supporteremail">Email Address:'.form_input($emaildata,set_value('suppoteremail')).'</label><br /><br />';
$pledgedata = array('name'=>'pledgedate','id'=>'pledgedate','size'=>'30','max_length'=>'20');
echo '<label for="pledgedate">Today\'s Date:'.form_input($pledgedata,set_value('pledgedate')).'</label><br /><br />';
$msgdata = array('name'=>'messagetxt','id'=>'messagetxt','col'=>'2','rows'=>'8');
echo '<label for="messagetext">Your Pledge:'.form_textarea($msgdata).'</label><br />';
$submitdata = array('name'=>'submitbtn','id'=>'submitbtn','value'=>'Send');
echo '<label for="submitbutton">'.form_submit($submitdata).'</label><br />';
echo form_close();
?>
</div>
<div id="errorsechoed">
<div class="ui-widget">
<div class="ui-state-error ui-corner-all" style="padding: 0 .7em; border: none;">
<?php echo validation_errors('<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>');?>
this is the form it's self. I have to make a presentation in a few hours and this form working is key. Thanks for y'all help.
E
There is a name mis-match between your form validation rules and the view html element.
The validation rule
$this->form_validation->set_rules('supportername','Name','trim|required|max_length[30]');
The HTML
$namedata = array('name'=>'supportname','id'=>'supportname','size'=>'30','max_length'=>'25');
echo '<label for="supportername">Your Name:'.form_input($namedata,set_value('supportname')).'</label><br /><br />';
Either change the validation rule name to 'supportname'
Or
Change the 'name' => 'supportname' to 'name' => 'supportername'
精彩评论