i have the following which is within a foreach loop and lists the unique code as a link:
<a href="" class="charcoal_link" style="line-height: 20px;" onclick="showMessageArea(this); return false;" >
<?php echo $uniqueCode1?><span class="pink_text"><?php echo $uniqueCode2?></span><?php echo $uniqueCode3?>
</a>
<form id="message_area" style="display:none" enctype="multipart/form-data" method="post" action="<?php echo ADDRESS; ?>messageSent.php?id=<?php echo $id_to ?>">
<textarea name="message" rows="10" cols="20"></textarea>
<input name="Submit" type="submit" value="Send"></input>
</form>
i want to pass the id of the uniquecode i clicked on but $id_to = the first link's id i also tried to pass $id_to as a hidden field inside the form tag but still it takes the id of the first uniquecode link regardless of which link i click on
please help?
thank you
You messed up with ".
Try with:
<form id="message_area" style="display:none" method="post" action="<?php echo ADDRESS; ?>messageSent.php?id=<?php echo $id_to ?>">
The form action can be another PHP script which can read POSTed variables. Add id as a hidden field to POST.
Related
I've been searching online on how to keep data in the form after submitting it. But after trying for awhile it still doesn't work as expected
This is the code that I tried:
<form action="process_login" method="post" target="_self">
<div class="login-field">
<input type="text" id="login-email-field" name="login-email-field" value="<?php echo isset($_POST["login-email-field"]) ? $_POST["login-email-field"] : ''; ?>" required />
<label class="login-email-label" for="login-email-field">Email/Username</label>
</div>
<div>
<button class="submit-button" type="submit">
Login
</button>
</div>
</form>
I also tried replacing the input (with a 'TEST' string in the value field if the POST is empty) but the 'TEST' string did not appear after submitting the form.
<input type="text" id="login-email-field" name="login-email-field" value="<?php echo isset($_POST["login-email-field"]) ? $_POST["login-email-field"] : 'TEST'; ?>" required />
Any help would be appreciated thanks!
Action specifies a URL to which the form’s data is sent when submitted.
If you want to stay on the same page you can leave it out
<form method="post" target="_self">
or set the name of the actual page.
<form action="actualPage.php" method="post" target="_self">
I want to pass a input value with a url.
<div class="modal-body">
<div id="myDiv" class="answer_list">
<form action="" id="usrform" method="get">
<textarea name="comment" style="width: 450px; height: 80px; form="usrform"></textarea>
<?php echo '<a href="reject_request.php?leave_id='.$id1.'&emp_id='.$emp_id.'">'?>
<button style="float: right" type="button" class="btn btn-primary" name="submit">
Proceed
</button></a></form></div>
</div>
Here I want to pass the textarea input value to 'reject_request.php' page with other variables. I couldn't able to find a way, Can any one help me !
Use method="POST" and action="reject_request.php"
<form action="reject_request.php" id="usrform" method="POST">
<textarea name="comment" id="comment"></textarea>
<input type="hidden" name="leave_id" id="leave_id" value="<?php echo $id1; ?>">
<input type="hidden" name="emp_id" id="emp_id" value="<?php echo $emp_id; ?>">
</form>
In reject_request.php you can access the form datas via $_POST['comment'],$_POST['leave_id'],$_POST['emp_id']
First of all, it is not advisable to pass long content in URL, as commented by #Dhara Parmar.
But if you want to do it,
<form action = "yourpage.php" .... as, again, commented by splash 58
As far as accessing those variables are concerned, you can access them via ASSOCIATIVE GLOBAL ARRAY $GET[KEY]
I have a user form that creates a drop down menu in Wordpress php. The form clears after it's submitted. How can I re-populate the form, when the edit pencil icon is clicked so the original info can be edited? As it is, because the form is cleared, it starts another menu.
There is one category and multiple names.
Thank you...if you need info, I will post it. I'm trying...
-A
I'm having a problem with this...as I mentioned, there is an "edit button" that creates a stupid edit form that some guy designed. I would like to repopulate the original form users filled out. I'm almost there. The info is is filled in boxes but they randomly overlay the drop down menu. It's not hitting inside the original form. "pp-website-edit" is the name of the "edit button".
<div class="pp-website-edit">
<form id="cat-edit-<?php echo $x; ?>" action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<input type="hidden" name="edit-category" value="<?php echo $indicat; ?>">
<INPUT TYPE="image" SRC="<?php bloginfo('url'); ?>/wp-content/themes/nebula/neb-style/images/arrow_045_small.png" HEIGHT="14" WIDTH="14" BORDER="0" ALT="Submit Form">
</form>
</div>
<div class="pp-website-edit">
<form id="wat-edit" action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<input type="hidden" name="edit-website" value="1">
<input type="hidden" name="ed-w-cat" value="<?php echo $indicat; ?>">
<input type="hidden" name="ed-w-label" value="<?php echo $finalresult[$y][name]; ?>">
<input type="hidden" name="ed-w-url" value="<?php echo $finalresult[$y][url]; ?>">
<INPUT TYPE="image" SRC="<?php bloginfo('url'); ?>/wp-content/themes/nebula/neb-style/images/arrow_045_small.png" HEIGHT="14" WIDTH="14" BORDER="0" ALT="Submit Form">
</form>
============================================================================
Site Category
Site Titles
Website url's
Forms that keep their values utilize some sort of peristance, either cookies, or a combination of querying the database for the values.
Either way you would need to then echo our the value inside the <input> tag.
I have a foreach loop listing the unique codes as links:
<a href="#" class="charcoal_link" value="<?php echo $id_to ?>" style="line-height: 20px;" onclick="showMessageArea(this); return false;">
<?php echo $uniqueCode1?>
<span class="pink_text"><?php echo $uniqueCode2?></span>
<?php echo $uniqueCode3?>
</a>
<input type="hidden" name="id" value="<?php echo $id_to ?>" />
<form id="message_area" style="display:none" method="post" action="<?php echo ADDRESS; ?>messageSent.php?id=<?php echo $id_to ?>">
<tr>
<td>
<input name="message" type="textarea" rows="10" cols="20" value="<?php echo $message ?>" />
</td>
<td>
<input name="Submit" type="submit" value="Send" />
</td>
</tr>
</form>
the above is also in another form tag: <form name = "contacts" method="post">
the action part works fine but in messageSent.php i do:
var_dump($_POST);
var_dump($_GET);
and the output gives me:
NULL
array(1) { ["id"]=> string(2) "36" }
Where is "message"?
"id" contains the wrong id. It is not the id of the unique code I clicked on.
Your HTML is invalid. Among the many errors you have made: You can't have a form inside a table but around a tr. The browser is error correcting by moving the form element to somewhere where it is allowed, and leaving the inputs alone (since inputs can be inside td elements).
Validate. Validate. Validate.
There are so many problems with that fragment of HTML that you have shared, that you would probably benefit from a beginner's guide to authoring webpages.
<a href="#" class="charcoal_link" value="<?php echo $id_to ?>" style="line-height: 20px;" onclick="showMessageArea(this); return false;">
<?php echo $uniqueCode1?>
<span class="pink_text"><?php echo $uniqueCode2?></span>
<?php echo $uniqueCode3?>
</a>
<form id="message_area" style="display:none" method="post" action="<?php echo ADDRESS; ?>messageSent.php?id=<?php echo $id_to ?>">
<input type="hidden" name="id" value="<?php echo $id_to ?>" />
<table>
<tr>
<td>
<textarea name="message" rows="10" cols="20"><?php echo $message ?></textarea>
</td>
<td>
<input name="Submit" type="submit" value="Send" />
</td>
</tr>
</table>
</form>
You cannot have a form inside a form.. you must do them seperate or else in the same form....
I fixed the HTML markup for you
I have this code in a foreach that lists uniquecode links:
<a id="<?php echo $id_to ?>" href="<?php echo ADDRESS; ?>messageSent.php?id=<?php echo $id_to ?>" class="charcoal_link" style="line-height: 20px;" onclick="showMessageArea(this); return false;" >
<?php echo $uniqueCode1?><span class="pink_text"><?php echo $uniqueCode2?></span><?php echo $uniqueCode3?>
</a>
<form id="message_area" style="display:none" method="post" action="<?php echo ADDRESS; ?>messageSent.php?id=<?php echo $id_to ?>">
<textarea name="message" rows="10" cols="20"></textarea>
<input name="Submit" type="submit" value="Send"></input>
</form>
this is what I get when I view the page source:
<a href="http://www-rainbowcode-mobi/messageSent.php?id=36" class="charcoal_link" style="line-height: 20px;" onclick="showMessageArea(this); return false;" >
KUZELJA<span class="pink_text">000</span>RC
</a>
<form id="message_area" style="display:none" method="post" action="http://www-rainbowcode-mobi/messageSent.php?id=36">
<textarea name="message" rows="10" cols="20"></textarea>
<input name="Submit" type="submit" value="Send"></input>
</form>
<a href="http://www-rainbowcode-mobi/messageSent.php?id=38" class="charcoal_link" style="line-height: 20px;" onclick="showMessageArea(this); return false;" >
ALANZIM<span class="pink_text">000</span>RC
</a>
<form id="message_area" style="display:none" method="post" action="http://www-rainbowcode-mobi/messageSent.php?id=38">
<textarea name="message" rows="10" cols="20"></textarea>
<input name="Submit" type="submit" value="Send"></input>
</form>
the problem is when the action fires and page goes to messageSent and I view page source again $id_to is NOT the id of the link I clicked on. It takes the first link's id regardless of which link I click on?
here the messageSent page source (I clicked on link with id 38 NOT 36):
where I have a print_r($_REQUEST) and it gives:
Array
(
[id] => 36
[message] => bj,nbgj,
[Submit] => Send
)
.
function showMessageArea(link)
{
var message_area = document.getElementById('message_area');
message_area.parentNode.removeChild(message_area);
link.parentNode.insertBefore(message_area, link.nextSibling);
message_area.style.display="block";
}
The problem is indeed the non-unique ids.
Try appending $to_id to the form ids, so that they are unique (e.g. <form id="message_area_<?php echo $to_id; ?>" ...).
And then update showMessageArea function to do this:
var message_area = document.getElementById('message_area_'+this.id);
This way you will be operating on the desired form element.
As a refactoring suggestion, I would suggest using a single form instead and make id parameter to be <input type='hidden' name='id' id='message_id' value=''> and set it's value from the showMessageArea(...) like this:
document.getElementById('message_id').value = this.id;
Shouldn't you have semi-colons after the php statements?
EDIT:
I think the problem is that there are two elements with the id "message_area", so it always refers to the first one. Try only having one form, and setting the action of that form when one of the links is clicked.
I don't know if this will fix it because I can't see an issue but could you try the following code:
<a id="<?php echo $id_to ?>" href="<?php echo ADDRESS; ?>messageSent.php class="charcoal_link" style="line-height: 20px;" onclick="showMessageArea(this); return false;" >
<?php echo $uniqueCode1?><span class="pink_text"><?php echo $uniqueCode2?></span><?php echo $uniqueCode3?>
</a>
<form id="message_area" style="display:none" method="post" action="<?php echo ADDRESS; ?>messageSent.php?id=<?php echo $id_to ?>">
<textarea name="message" rows="10" cols="20"></textarea>
<input type="hidden" name="id" value="<?php echo $id_to ?>" />
<input name="Submit" type="submit" value="Send" />
</form>
And then try print_r($_POST)
EDIT:
Okay, following your comment Helloise, I believe the following may work:
<a id="messageid_<?php echo $id_to ?>" href="javascript:void(0);" class="charcoal_link" style="line-height: 20px;" onclick="showMessageArea(this,'<?php echo $id_to ?>'); return false;" >
<?php echo $uniqueCode1?><span class="pink_text"><?php echo $uniqueCode2?></span><?php echo $uniqueCode3?>
</a>
<form id="message_area" style="display:none" method="post" action="<?php echo ADDRESS; ?>messageSent.php">
<textarea name="message" rows="10" cols="20"></textarea>
<input name="Submit" type="submit" value="Send" />
<input type="hidden" id="message_id" name="id" value="" />
</form>
<script type="text/javascript">
function showMessageArea(link,messageId)
{
document.getElementById('message_id').value=messageId;
message_area.parentNode.removeChild(message_area);
link.parentNode.insertBefore(message_area, link.nextSibling);
document.getElementById('message_area').style.display="block";
}
</script>
So, here the main point is to have one form as you have stated but to pass the id we are using into the javascript function. From there, you can set the value of the hidden input which will then be included in the POST values.
Try something like this:
after quick peruse...
your missing $ before ADDRESS. It should be $ADDRESS. I assume thats a variable (ignore this, overlooked its just a constant)
your missing semi-colon after many lines of php.
<a id="<?php echo $id_to; ?>"
href="<?php echo $ADDRESS;?>messageSent.php?id=<?php echo $id_to; ?>"
class="charcoal_link"
style="line-height: 20px;"
onclick="showMessageArea(this); return false;"
<?php echo $uniqueCode1;?>
<span class="pink_text">
<?php echo $uniqueCode2?>
</span>
<?php echo $uniqueCode3;?>
></a>
<form id="message_area" style="display:none" method="post" action="<?php echo $ADDRESS; ?>messageSent.php?id=<?php echo $id_to; ?>">
<textarea name="message" rows="10" cols="20"></textarea>
<input name="Submit" type="submit" value="Send"></input>
</form>