Welcome Guest, Not a member yet? Register   Sign In
Codeigniter Code validating through Javascript
#1

[eluser]thedevilz[/eluser]
Hello,
I made a simple form, and passing it back to the controller

<form action="http://localhost/CodeIgniter/index.php/Contact" name="fom" method="post">

While if i use form_open('Contact');
it sends fine

Whether
<?php echo form_open('Contact','TRUE','fom'); ?>
&
<form action="http://localhost/CodeIgniter/index.php/Contact" method="post">

generates the same code except onsubmit function.
After Interprate it shows same code but the second line doesnot pass the form data to controller
_____________________________________________________________________________________________
here is the whole code of view::



<?php echo validation_errors(); ?>
<?php echo form_open('Contact','TRUE','fom'); ?>

[removed]
function validate_form ( )
{
if (document.fom.f_name.value == "" )
{
alert("Kindly Enter your name:");
return FALSE;
}
else
return TRUE;
}


//<form action="http://localhost/CodeIgniter/index.php/Contact" method="post">
[removed]
First Name
<input type="text" name="f_name" value="<?php echo set_value('f_name'); ?>"
Last Name
<input type="text" name="l_name" class="smallInput" size="16" value="<?php echo set_value('l_name'); ?>" />
Email</td>
&lt;input name="e-mail" class="smallInput" size="16" value="&lt;?php echo set_value('e-mail'); ?&gt;"/&gt;&lt;/td>
&lt;input type="submit" value="Submit" /&gt;&lt;/td>

&lt;input type="reset" name="button2" id="button2" value="Reset" /&gt;&lt;/td>
&lt;/form&gt;


Further I am bit confused if we call the method form_open(), what will the name of our form?Can we not set the name of the form through form_open()??

I have loaded the file in controll
$this->load->helper(array('form', 'url', 'html'));

Thanks in advance
need ur guidence
#2

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums.

When you post code, please put the code inside [code][/code] tags, as it makes it easier for us to read.

I'm sorry, but I don't understand the problem your experiencing, please could you try to explain it a bit more clearly?

As for passing extra parameters over to the form, you can do that via the second parameter:

Code:
$attributes = array('name' => 'my_form');
echo form_open('contact', $attributes);
#3

[eluser]thedevilz[/eluser]
I am extremly sorry for that, I donot have idea of these code tags.
i will try to explain

I made a form
Code:
&lt;?php echo validation_errors(); ?&gt;
&lt;?php echo form_open(‘Contact’,‘TRUE’,‘fom’); ?&gt;

First Name          
  &lt;input type=“text” name=“f_name” value=”&lt;?php echo set_value(‘f_name’); ?&gt;”
Last Name
  &lt;input type=“text” name=“l_name” class=“smallInput” size=“16” value=”&lt;?php echo set_value(‘l_name’); ?&gt;” >
  Email</td>
  &lt;input name=“e-mail” class=“smallInput” size=“16” value=”&lt;?php echo set_value(‘e-mail’); ?&gt;”/&gt;&lt;/td>
    &lt;input type=“submit” value=“Submit” /&gt;&lt;/td>
    
    &lt;input type=“reset” name=“button2” id=“button2” value=“Reset” /&gt;&lt;/td>
    &lt;/form&gt;

This is the view file.
I am passing data back to the controller through
Code:
&lt;?php echo form_open(‘Contact’,‘TRUE’,‘fom’); ?&gt;
and it works fine

if I try to pass data manually or you can say through simple html by using form tag like
Code:
&lt;form action=“http://localhost/CodeIgniter/index.php/Contact” method=“post”&gt;

it doesnot send form data to controller.
All i am doing this because I want to first validate data through JavaScript.
and then want to post data to the controller named:: Contact.

And i am very thanks full to you.

Regards
sK
#4

[eluser]Dam1an[/eluser]
The easiest way to do this, is to just leave it with the form_helper Tongue
If you want to specify an absolute URL, view the source when using the helper, and see what the opening form decleration is, then just copy that straight into your view
#5

[eluser]thedevilz[/eluser]
First of all thanks alot. :roll:
well first I tried to pass the refrence as well. like:
Code:
&lt;form action=“&lt;?php print site_url(/Contact)” name=“fom” method=“post”&gt;

and As you said I checked the source code it shows the same, as

Code:
&lt;?php echo form_open(‘Contact’,‘TRUE’,‘fom’); ?&gt;
but my problem is that I want to validate the date through JavaScript first.
how can I pass data back to the controller with validating the data by JavaScript by use on onsubmit function.
like If I want to run this code, It doesnot run

Code:
&lt;form action="http://localhost/CodeIgniter/index.php/Contact" method="post"&gt;

If I use the above code it doesnot Post data back to the controller.
#6

[eluser]TheFuzzy0ne[/eluser]
Do you get a 404 error?
#7

[eluser]thedevilz[/eluser]
No it doesnot show any error. . ..
page displays well
i just got problem when I press the submit button
it work nothing.
donot show any error
donot do any kind of action
if I use this line of code:
Code:
&lt;form action="http://localhost/CodeIgniter/index.php/Contact" method="post"&gt;

If you say so may i give you the whole script?

Thanks again for your time.
#8

[eluser]Dam1an[/eluser]
Firstly, would you not put the onsubmit on the button? so it has nothing to do with the form opening
Secondly, Seeing as you're using JS validation, why not do it in real time (so it detects as they type), that way, its all valid by the time the submit (you might want to disable submit or something)
#9

[eluser]TheFuzzy0ne[/eluser]
You need to tie your JavaScript into the form, either by using onclick in your submit button, onsubmit in your form, or dynamically using JavaScript.
#10

[eluser]tkyy[/eluser]
you can create a seperate ajax-only function that could only do form validation and onsubmit, post to it. if there are errors then return a json response which you can add back into the page. if there were no errors then allow the form to submit, just change onsubmit=return(false); and bind the object to the submit action (jquery)

of course you will run the same validation params on the server, so better off storing it into a configuration file.

this way you are using consistent validation (ci on the js and on the server)




Theme © iAndrew 2016 - Forum software by © MyBB