Welcome Guest, Not a member yet? Register   Sign In
Form not calling function, instead refreshing page with querystring
#1

[eluser]ReasonMan[/eluser]
I followed the blog tutorial when I first started out with CI, and have since built off of it and made alot of changes, except in the area of commenting, which i'm addressing now. When I hit submit on my form, instead of calling the action function i've defined, it just refreshes the page and puts all my postdata in the url as a querystring. I can call my function directly and it works fine(aside from throwing the expected db error about having null data). When I first set it up, it worked fine, but i'm so far into all of my changes, I can't possibly think of what change set this off. This is generally what I get when I click the submit button:

cmd=_s-xclick&hosted_button_id=2278616&postid=38&author=Brandon&body=Test+comment.

Obviously author, body and postid are different from post to post. My form is as follows:

Code:
<?=form_open('blog/commentInsert');?>
<?=form_hidden('postid', $this->uri->segment(3));?>
<p>&lt;input type="text" name="author" /&gt;&lt;/p>
<p>&lt;textarea rows="10" name="body"&gt;&lt;/textarea></p>
<p>&lt;input type="submit" value="Post" /&gt;&lt;/p>
&lt;/form&gt;

When viewing the source the form looks as it should. The only thing I could think of is that I had set a rule in my url rewriting that strips out "index.php", but changing it back doesn't fix it.
#2

[eluser]Jameson.[/eluser]
Seem like method=post attribute is missing from your form, forcing it to send data via GET, not POST.
#3

[eluser]pistolPete[/eluser]
[quote author="ReasonMan" date="1239792335"]When viewing the source the form looks as it should.[/quote]
Could you please post the generated HTML?

[quote author="Jameson." date="1239800299"]Seem like method=post attribute is missing from your form ...[/quote]

It should be there, because if no $attributes is set, POST is the default value:
Code:
function form_open($action = '', $attributes = '', $hidden = array())
{
   $CI =& get_instance();

   if ($attributes == '')
   {
      $attributes = 'method="post"';
   }
...
#4

[eluser]ReasonMan[/eluser]
Yes, the method is set to post, even when I create the form manually the old fashioned way it doesn't work.

Code:
&lt;form action="http://localhost/blog/commentInsert" method="post"&gt;
    &lt;input type="hidden" name="postid" value="" /&gt;
    <p>&lt;input type="text" name="author" /&gt;&lt;/p>
    <p>&lt;textarea rows="10" name="body"&gt;&lt;/textarea></p>
    <p>&lt;input type="submit" value="Post" /&gt;&lt;/p>
&lt;/form&gt;

Looking at it now, that postid is empty when it should contain the id of the currently selected post. As reference, the code that makes the form is in the OP. But that shouldn't cause it to not call the function, should it? I would imagine all that would happen in that case is it throws back a db error for a null field.

Edit: Actually, the above was my fault. I forgot that I changed my uri to reflect the article name and not the id so that segment wasn't there. I fixed that issue, but i'm still having the problem with actually posting.
#5

[eluser]Jameson.[/eluser]
[quote author="pistolPete" date="1239805439"]
[quote author="Jameson." date="1239800299"]Seem like method=post attribute is missing from your form ...[/quote]

It should be there, because if no $attributes is set, POST is the default value[/quote]

True. It should be there, but it is not, judging by the way form behaves. ReasonMan, it is simpler and quicker at this stage to publish just this page somewhere for us to have a look at it in its entirety. Because clearly thing don't go how they should, for an (unknown) number of unknown reasons. Maybe (just maybe) you use some js-plugin that messes with form's attributes, or maybe you forgot to delete declaration of another form inside the form in question and the former gets submitted instead of the one that should.
#6

[eluser]ReasonMan[/eluser]
[quote author="Jameson." date="1239867039"][quote author="pistolPete" date="1239805439"]
[quote author="Jameson." date="1239800299"]Seem like method=post attribute is missing from your form ...[/quote]

It should be there, because if no $attributes is set, POST is the default value[/quote]

True. It should be there, but it is not, judging by the way form behaves. ReasonMan, it is simpler and quicker at this stage to publish just this page somewhere for us to have a look at it in its entirety. Because clearly thing don't go how they should, for an (unknown) number of unknown reasons. Maybe (just maybe) you use some js-plugin that messes with form's attributes, or maybe you forgot to delete declaration of another form inside the form in question and the former gets submitted instead of the one that should.[/quote]

You know what, the latter was exactly it, and I feel so dumb. I'm converting my site from ASP.NET to PHP and I had copied my header contents from the master file. I don't recall why, but I had my main content embedded in a form that had no action(required .Net nonsense) and that was opened in the header and closed in the footer. Deleting that container form allowed the comment form to post to the correct place.

Thanks all for the help. I'm going to have to pay more attention to my source when I copy/paste.




Theme © iAndrew 2016 - Forum software by © MyBB