Jump to content

Recommended Posts

Hi I am trying to split a form as shown in this simple code. I tried what I thought should work but obviously it is not working. 

 

This submits the first part of the form but does not go to the second part of the form. So First name, Last names and Age are submitted but email and cell are not and it throws a undefined index warning for those.

 

Can someone please take a look at this and suggest if what I am trying to do can be accomplished using PHP. 

 

Thanks

<?php 
if(isset($_POST['submit']) && $_POST['submit'] == 'Submit')
{
echo"<br> First Name = ".$_POST['fname']."<br>" ;
echo"Last Name = ".$_POST['lname']."<br>" ;
echo"Age = ".$_POST['age']."<br>" ;
echo"Email = ".$_POST['email']."<br>" ;
echo"Cell = ".$_POST['cell']."<br>" ;

}

?>

<html>
<head> <title> WOW </title></head>

<body>
<table>

<form id="form1" action = "splitform.php" method="post">
<th> TEST </th> 
<tr><td>First Name : </td> <td><Input type='text' name = 'fname'></td></tr>
<tr><td>Last Name : </td> <td><Input type='text' name = 'lname'></td></tr>
<tr><td>AGE : </td> <td><Input type='text' name = 'age'></td></tr>
</form>

<form id ="form1" action = "splitform.php" method="post">
<tr><td>Email : </td> <td><Input type='text' name = 'email'></td></tr>
<tr><td>Cell: </td> <td><Input type='text' name = 'cell'></td></tr>
</form>

<tr><td><Input type="submit" name = "submit" value = "Submit" form = "form1"></tr></td>


</table>
</body>

</html>
Link to comment
https://forums.phpfreaks.com/topic/288894-split-a-form-on-the-same-page/
Share on other sites

Yeah why would you want to split that form up?  It's a fairly pointless idea in this case.  The only real times you do that is if there are many steps to filling a form out and you want to save the progess for the client.  Plus you have invalid html by having the id the same between the 2 forms.  Id's must be unique to the page.

Normally when I see 'undefined index' I straight away look for isset().

 

Also remove;

</form>
<form id ="form1" action = "splitform.php" method="post">

No sense having two forms going to the same place and same collective data.

 

Maybe let us know why your trying to split the form and we might have a better solution for you.

 

As far as I can tell only reason to split a form is to have form steps, ie name / email : submit -> age / sport: submit -> Confirmation. (But seems pointless unless huge form)

 

 

 

Edited by Ansego
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.