0

What a problem

I'm new in php, and I faced a very trivial problem: how to get form's name in php?

What I've tried:

$name = $form['name'];
print_r($name); // echo stuff like SimpleXMLElement Object ( [@attributes] => Array ( [name] => feedback [description] =>...

Question:

How can I get only name of the form?

2
  • $name = $form->attributes()->name; Please read the documentation. Commented Nov 2, 2013 at 18:08
  • 1
    Try $name = $_POST['name']; which is "one" way of doing it, assuming you're using a POST request. You can also use $_GET or $_REQUEST instead of $_POST yet I tend to think that Amal's answer is what's to be used. Try posting your full code so we can see exactly what you have. 2 lines of code is a bit vague. Commented Nov 2, 2013 at 18:08

2 Answers 2

1

I don't know where you're getting the SimpleXML object from, but to access the name attribute, you can use the attributes() method:

echo $xml->attributes()->name;
Sign up to request clarification or add additional context in comments.

3 Comments

Why just not use $_POST['name'] / $_GET['name'] ?
@IliaRostovtsev: I think the OP is trying to access the attribute name from the SimpleXML object. He just listed $_POST['name'] as one method he tried.
@AmalMurali That's what I thought as well. Notice my mention? ;-)
0

To identify the submitted form, you can use:

  • A hidden input field OR.
  • The name or value of the submit button.

The name of the form is not sent to the server as part of the POST data.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.